我的所有图像都有以下内容/images/500x500/
。/images/250x250/
我需要将图像大小调整为 250x250 并让它们使用相同的文件名进入。
它不会在新目录中创建新图像,而是替换同一目录中的大图像?
<?php
$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 = 250;
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, $outputFile, 100);
$outputFile =
realpath(
pathinfo($file, PATHINFO_DIRNAME)
. '/../250x250/'
) . pathinfo($file, PATHINFO_BASENAME);
}
}
?>