嗨我想在顯示細節部分時調整圖像大小。爲此,我檢查了許多PHP腳本,但它不能在我的語言環境中工作。某些顯示圖像路徑的腳本必須以/開頭,但是當我給出它的展示圖像未找到時。另外,大多數腳本演示頁面都顯示假圖像。使用PHP5和JQuery調整圖像尺寸
-1
A
回答
2
最好的辦法是同時上傳圖像剪切圖像。請使用GD庫找到下面的圖像裁剪代碼,它可以幫助你。
<?php
function createThumb($upfile, $dstfile, $max_width, $max_height){
$size = getimagesize($upfile);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width/$width;
$y_ratio = $max_height/$height;
if(($width <= $max_width) && ($height <= $max_height)) {
$tn_width = $width;
$tn_height = $height;
} elseif (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
} else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
if($size['mime'] == "image/jpeg"){
$src = ImageCreateFromJpeg($upfile);
$dst = ImageCreateTrueColor($tn_width, $tn_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height,$width, $height);
imageinterlace($dst, true);
ImageJpeg($dst, $dstfile, 100);
} else if ($size['mime'] == "image/png"){
$src = ImageCreateFrompng($upfile);
$dst = ImageCreateTrueColor($tn_width, $tn_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height,$width, $height);
Imagepng($dst, $dstfile);
} else {
$src = ImageCreateFromGif($upfile);
$dst = ImageCreateTrueColor($tn_width, $tn_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height,$width, $height);
imagegif($dst, $dstfile);
}
}
//usage
if(isset($_FILES['upload_Image']['name']) && $_FILES['upload_Image']['name']!=='') {
$ext = substr($_FILES['upload_Image']['name'], strpos($_FILES['upload_Image']['name'],'.'), strlen($_FILES['upload_Image']['name'])-1);
$imgNormal = time().$ext;
$normalDestination = "Photos/Orignal/" . $imgNormal;
$httpRootLarge = "Photos/Large/" . $imgNormal;
$httpRootSmall = "Photos/Small/" . $imgNormal;
$httpRootThumb = "Photos/Thumb/" . $imgNormal;
move_uploaded_file($_FILES['upload_Image']['tmp_name'], $normalDestination);
createThumb($normalDestination,$httpRootLarge,680,604); #For 604x604 Image
createThumb($normalDestination,$httpRootSmall,500,300); #For 500x300 Image
createThumb($normalDestination,$httpRootThumb,130,100); #For 130x100 Image
}
?>
0
我想你需要ImageMagick。你可以在Google中找到很多例子,我只有Perl例子。
1
有兩種選擇:
- 創建圖像的縮略圖(通過PHP圖形庫),並將其存儲(獲得更好的性能)。
- 使用PHP圖形庫動態調整圖像大小並顯示它。
您也可以參考此頁面瞭解詳情:http://php.net/manual/book.image.php
0
傢伙形成NETTUTS有很大的嘖嘖關於這個主題:Image Resizing Made Easy with PHP :)
相關問題
- 1. 使用php調整圖像尺寸
- 2. Node.js調整圖像尺寸
- 3. 調整尺寸圖像
- 4. 調整圖像尺寸PHP
- 5. 使用Graphics.DrawImage調整圖像尺寸結果尺寸調整不正確
- 6. 使用Jquery Animate調整圖像的尺寸
- 7. 使用jQuery動畫將圖像調整爲原始尺寸
- 8. 使用CSS調整圖像大小和裁剪尺寸
- 9. 通過javascript調整圖像大小或調整圖像尺寸
- 10. 將圖像調整爲更小尺寸
- 11. 調整SVG背景圖像的尺寸
- 12. Graphics32:調整大量圖像的尺寸
- 13. 調整圖像尺寸iPhone SDK
- 14. Sitecore的8 RTE圖像尺寸調整
- 15. Android根據設備的屏幕尺寸調整圖像尺寸
- 16. 當屏幕尺寸減小時自動調整圖像尺寸
- 17. 根據圖像尺寸調整ImageViews的尺寸
- 18. JQuery - 試圖調整Fancybox的尺寸
- 19. 使用Powerpoint vba調整圖片尺寸
- 20. woocommerce使用全尺寸圖像,調整大小,縮略圖
- 21. jquery圖像替換屏幕尺寸調整
- 22. 根據jQuery中的尺寸調整每個圖像的大小
- 23. 使用php調整圖像的尺寸或用strech進行調整?
- 24. 使用GD調整圖像尺寸並保留長寬比
- 25. 使用Paperclip調整默認圖像的尺寸
- 26. 使用as3調整Flex中的圖像的尺寸
- 27. 僅使用Tkinter調整pgm圖像的尺寸
- 28. 使用低質量的Codeigniter調整圖像尺寸
- 29. 使用Picasso調整圖像尺寸並添加到HttpPost
- 30. tensorflow - 調整尺寸
你自己寫了嗎? http://pastebin.com/Ed2YHV6w – mplungjan 2011-06-22 09:18:06