我想调整大小 - $artfile
,并将商店从$dest
开始存放到$start_x, $start_y
。
$dest
包含一个框架。 $artfile
需要适合框架,所以我需要调整它。
我的代码是:
imagecopy($dest, $art_file, $start_x, $start_y, 0, 0, $new_width, $new_height); // works fine but to test resize
$dest = my destination resource
$artfile = resource that I want to patch with $destination
$new_width, $new_height = I want $art_file to be resized to this value, without trimming off or cropping.
我的问题是:
对于任何超过$new_height
或$new_width
维度的图片,剪掉的图片越多。我想将整个集调整为$new_height
或$new_width
。
任何帮助?
答案 0 :(得分:0)
玩这个,希望它可以帮助你一些;
<?php
Function createthumbnail($src=null,$newHeight=null) {
$srcimg = imagecreatefromjpeg($src);
$srcsize = getimagesize($src);
$dest_y = $newHeight;
$dest_x = ($newHeight / $srcsize[1]) * $srcsize[0];
$thumbimg = imagecreatetruecolor($dest_x, $dest_y);
imagecopyresampled($thumbimg,$srcimg,0,0,0,0,$dest_x,$dest_y, $srcsize[0], $srcsize[1]);
$thumbimg = imagejpeg($thumbimg,$src);
return $thumbimg;
}
?>
你可以这样称呼它
<?php
resizedImage = createthumbnail(urlOfFileToResize,newHeight);//newHeight would be like 1 or 50 or 1000......
?>
现在您调整大小的图像将存储在resizedImage
中欢迎你。