のすべての画像に対して次のように設定しています/images/500x500/
。画像のサイズを 250x250 に変更/images/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);
}
}
?>