ここにこのコードがあります
imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width,$thumb_width,$width,$height);
基本的に私がやろうとしているのは、画像をアップロードして幅のサイズを変更し、幅に基づいて高さを調整することです。
これもやってみた
imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width,$thumb_width,$width);
高さなしでこのエラーが発生しました
Warning: Wrong parameter count for imagecopyresampled() in /home/content/44/8713044/html/admin/Categories.php on line 63
$width
これは、および$height
変数が由来する現在のコードです。
if($width> $height) {
$x = ceil(($width - $height) / 2 );
$width = $height;
} elseif($height> $width) {
$y = ceil(($height - $width) / 2);
$height = $width;
}
任意の助けをいただければ幸いです, 高度に感謝します, J
ここに完全な機能があります..
function create_thumbnail($source,$destination, $thumb_width) {
$percent = 0.5;
$size = getimagesize($source);
$width = $size[0];
$height = $size[1];
$x = 0;
$y = 0;
if($width> $height) {
$x = ceil(($width - $height) / 2 );
$width = $height;
} elseif($height> $width) {
$y = ceil(($height - $width) / 2);
$height = $width;
}
$new_image = imagecreatetruecolor($thumb_width,$thumb_width)or die('Cannot Initialize new GD image stream');
$extension = get_image_extension($source);
if($extension=='jpg' || $extension=='jpeg')
$image = imagecreatefromjpeg($source);
if($extension=='gif')
$image = imagecreatefromgif($source);
if($extension=='png')
$image = imagecreatefrompng($source);
imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width,$thumb_width,$width,$height);
if($extension=='jpg' || $extension=='jpeg')
imagejpeg($new_image,$destination);
if($extension=='gif')
imagegif($new_image,$destination);
if($extension=='png')
imagepng($new_image,$destination);
}
これ$thumb_width
は600で、これは私の画像600 * 600を返します