画像サイズを600px*500pxから60px*50pxに縮小してから、50px*50pxにトリミングしたいと思います。コードには2つのグループがあります。1つは画像のサイズを縮小するためのもので、もう1つは画像をトリミングするためのものです。問題は、それらが別々に機能することです。この2つのコードグループを組み合わせて、一緒に機能させるにはどうすればよいでしょうか。以下は私のコードです:
<?php
//codes of group A - Reduce the size of image from 600px * 500px to 60px * 50px
$save2 = "images/users/" . $image_name_2; //This is the new file you saving
list($width2, $height2) = getimagesize($file) ;
$modwidth2 = 50;
$diff2 = $width2 / $modwidth2;
$modheight2 = $height2 / $diff2;
$tn2 = imagecreatetruecolor($modwidth2, $modheight2) ;
$image2 = imagecreatefromjpeg($file) ;
imagecopyresampled($tn2, $image2, 0, 0, 0, 0, $modwidth2, $modheight2, $width2, $height2) ;
imagejpeg($tn2, $save2, 100) ;
//codes of group B - Crop the image from 60px * 50px to 50px * 50px
$save3 = "images/users/" . $image_name_3;
list($width3, $height3) = getimagesize($file) ;
$modwidth3 = 60;
$diff3 = $width3 / $modwidth3;
$modheight3 = $height3 / $diff3;
$left = 0;
$top = 0;
$cropwidth = 50; //thumb size
$cropheight = 50;
$tn3 = imagecreatetruecolor($cropwidth, $cropheight) ;
$image3 = imagecreatefromjpeg($file) ;
imagecopyresampled($tn3, $image3, 0, 0, $left, $top, $cropwidth, $cropheight, $modwidth3, $modheight3) ;
imagejpeg($tn3, $save3, 100) ; //save the cropped image
?>
上記の2つのグループのコードからわかるように、最初のグループは写真のサイズを変更してから、フォルダーに保存します。コードの2番目のグループは、写真をトリミングしてから、フォルダーにも保存します。私の質問は...コードの最初のグループが画像のサイズを変更した後、トリミングする前にフォルダに保存する必要がありますか?必要に応じて、コードの2番目のグループのフォルダーからサイズ変更された写真を取得してトリミングするために、新しいコード行を記述する必要がありますか?必要がない場合は、写真のサイズを変更した後、写真をコードの2番目のグループに渡してトリミングするにはどうすればよいですか?