0
我已經做了很多關於這個問題的搜索,仍然... 我有一個PHP代碼來調整圖像庫Gd的大小,但麻煩的是,調整大小後它不顯示圖像。 這是代碼Php調整大小與圖像GD不顯示圖像,但調整大小
文件名resize.php
<?php
/*
* PHP function to resize an image maintaining aspect ratio
* http://salman-w.blogspot.com/2008/10/resize-images-using-phpgd-library.html
*
* Creates a resized (e.g. thumbnail, small, medium, large)
* version of an image file and saves it as another file
*/
define('THUMBNAIL_IMAGE_MAX_WIDTH', 150);
define('THUMBNAIL_IMAGE_MAX_HEIGHT', 150);
function generate_image_thumbnail($source_image_path, $thumbnail_image_path)
{
list($source_image_width, $source_image_height, $source_image_type) = getimagesize($source_image_path);
switch ($source_image_type) {
case IMAGETYPE_GIF:
$source_gd_image = imagecreatefromgif($source_image_path);
break;
case IMAGETYPE_JPEG:
$source_gd_image = imagecreatefromjpeg($source_image_path);
break;
case IMAGETYPE_PNG:
$source_gd_image = imagecreatefrompng($source_image_path);
break;
}
if ($source_gd_image === false) {
return false;
}
$source_aspect_ratio = $source_image_width/$source_image_height;
$thumbnail_aspect_ratio = THUMBNAIL_IMAGE_MAX_WIDTH/THUMBNAIL_IMAGE_MAX_HEIGHT;
if ($source_image_width <= THUMBNAIL_IMAGE_MAX_WIDTH && $source_image_height <= THUMBNAIL_IMAGE_MAX_HEIGHT) {
$thumbnail_image_width = $source_image_width;
$thumbnail_image_height = $source_image_height;
} elseif ($thumbnail_aspect_ratio > $source_aspect_ratio) {
$thumbnail_image_width = (int) (THUMBNAIL_IMAGE_MAX_HEIGHT * $source_aspect_ratio);
$thumbnail_image_height = THUMBNAIL_IMAGE_MAX_HEIGHT;
} else {
$thumbnail_image_width = THUMBNAIL_IMAGE_MAX_WIDTH;
$thumbnail_image_height = (int) (THUMBNAIL_IMAGE_MAX_WIDTH/$source_aspect_ratio);
}
$thumbnail_gd_image = imagecreatetruecolor($thumbnail_image_width, $thumbnail_image_height);
imagecopyresampled($thumbnail_gd_image, $source_gd_image, 0, 0, 0, 0, $thumbnail_image_width, $thumbnail_image_height, $source_image_width, $source_image_height);
imagejpeg($thumbnail_gd_image, $thumbnail_image_path, 90);
imagedestroy($source_gd_image);
imagedestroy($thumbnail_gd_image);
return true;
}
generate_image_thumbnail('sql/max.jpg', 'sql/thumbnail_image_width_max.jpg');
?>
而在index.php文件,我沒有這樣的事情
<img src="resize.php"/>
麻煩的是,它調整圖像大小,但它不顯示它當我做<img src="resize.php"/>
,但圖像存在,如<img src="sql/thumbnail_image_width_max.jpg"/>
存在。但是,如果沒有做<img src="resize.php"/>
我甚至不知道如何調整圖像大小,這樣我可以直接可能與<img src="sql/thumbnail_image_width_max.jpg"/>
顯示它或直接與<img src="resize.php"/>.
感謝您的幫助顯示。並且希望這個時候我的問題不會再以負數標記。
非常感謝Kraysak。真的很感謝你。這是工作 –