[英]Resize/scale all images in a directory and save them
我正在制作一个小脚本,该脚本遍历目录中的所有图像,检查它们的宽度,如果它们不是此宽度,请调整大小。
我到目前为止所拥有的是:
$files = glob("*.{png,jpg,jpeg}", GLOB_BRACE);
foreach ($files as $file)
{
// get the image size
$imagesize = getimagesize($file);
$width_orig = $imagesize[0];
$height_orig = $imagesize[1];
$dst_w = 900;
if($width_orig != $dst_w)
{
$dst_h_multiplier = $dst_w / $width_orig;
$dst_h = $dst_h_multiplier * $height_orig;
$dst = imagecreatetruecolor($dst_w, $dst_h);
$image = imagecreatefromjpeg($file);
imagecopyresampled($dst, $image, 0, 0, 0, 0, $dst_w, $dst_h ,$width_orig, $height_orig);
imagejpeg($dst,null,100);
}
}
脚本似乎可以正常执行-但执行该脚本的同一目录中的图像文件未修改。
我在这里想念什么? 我该如何调试?
您不应将null作为第二个参数传递。 传递您的文件名
imagejpeg($dst,$file.'edited',100);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.