PHP を使用して画像のサイズを変更しようとしていますが、新しい画像に適切な名前を付ける方法がわかりません。データベース内の画像のテーブルを見ると、ID を持つエントリがありますが、名前はありません。
他に見るべきものがあれば教えてください。現時点では、imagecopyresampled の入力が正しくないと想定しています。$formattedImage の名前をエコーしようとしても、何も起こりません。imagejpeg を使用する前にさらに 1 段階バックアップして、$blankImage の名前をエコーしても、何も起こりません。
これが私のコードです。
function chgSize($image, $width, $height){
$name = $image["name"]; //this is displaying the file name correctly
$temp = $image["tmp_name"];
$imgContents = imagecreatefromstring(file_get_contents($temp));
$blankImage = imagecreatetruecolor(100,100);
if(imagecopyresampled($blankImage, $imgContents, 0, 0, 0, 0, 100, 100, $width, $height)){
$formattedImage = imagejpeg($blankImage, $name);
$this->saveImage($formattedImage);
}
}
function saveImage($image){
$newName = $image["name"];
move_uploaded_file($image['tmp_name'], "/Applications/XAMPP/xamppfiles/htdocs/images/" . $newName);
mysql_query("insert into images VALUES('null','$newName')");
echo "Stored in: " . "/Applications/XAMPP/xamppfiles/htdocs/images/" . $newName;
}