我需要创建将图像制作成不同尺寸的过程并将它们移动到相应的文件夹中。下面的代码适用于某些图像,而不适用于某些图像。有些图像在子文件夹中被重命名,有些不是。正在创建一些图像,有些图像不是。我已经对单个图像进行了单元测试并且它有效。但是当我在服务器上运行它时,我遇到了上述问题。有超过 500 张图像需要处理。我无法理解我哪里出错了。请帮忙。
$arr=Array();
$arr["popup"]=Array("width"=>228,"height"=>304);
$arr["zoom"]=Array("width"=>1500,"height"=>2000);
$source = imagecreatefromjpeg($file_path);
list($width, $height) = getimagesize($file_path);
foreach($arr as $image_type=>$dimention){
echo "<br> $image_type : ";
$temp_folder_name=$image_type;
$temp_folder_path='../prod_images/'.$folder_name.'/'.$temp_folder_name;
//check if directory exists if not then create else traverse
if (!file_exists($temp_folder_path)):
mkdir($temp_folder_path);
else:
$files = glob($temp_folder_path.'/'.$filename);
if (!empty($files))){
echo "<br/>Images exists";
$curr_dt = date('Ymd_His');
$dt = '_'.$curr_dt;
$file_arr = explode(".",$filename);
$new_filename = $file_arr[0].$dt.'.'.$file_arr[1];
$oldname = '../prod_images/'.$folder_name.'/'.$temp_folder_name.'/'.$filename;
echo "<br>Old Name : ".$oldname;
$newname = '../prod_images/'.$folder_name.'/'.$temp_folder_name.'/'.$new_filename;
echo "<br>New Name : ".$newname;
rename($oldname,$newname);
}else{
echo "<br/>Images does not exist";
}
endif;
$curr_width=$dimention["width"];
$curr_height=$dimention["height"];
echo "<br> $image_type - $curr_width - $curr_height";
$temp_image = imagecreatetruecolor($curr_width, $curr_height);
//imagecopyresized($temp_image,$source, 0, 0, 0, 0, $curr_width, $curr_height, $width, $height);
imagecopyresampled($temp_image,$source, 0, 0, 0, 0,$curr_width, $curr_height, $width, $height);
imagejpeg($temp_image,$temp_folder_path."/".$filename);
imagedestroy($temp_image);