Can you please tell me how to save the background image? And then after resizing the background is black! I started working with GD couple of days ago.

 <?php define("UPLOAD_DIR","upload/"); define("TEMP_DIR",$_FILES["image"]["tmp_name"]); define("WIDTH",300); define("HEIGHT",200); if(!empty($_FILES) && $_FILES["image"]["error"] == 0){ $uploaded = move_uploaded_file(TEMP_DIR,UPLOAD_DIR.$_FILES["image"]["name"]); } $originalImage = UPLOAD_DIR.$_FILES["image"]["name"]; $createJpeg = imagecreatefromjpeg($originalImage); $imageSize = getimagesize($originalImage); $imageHeight = $imageSize[1]; $imageWidth = $imageSize[0]; //Проверка высоты и ширины изображения if($imageHeight>HEIGHT && $imageWidth>WIDTH){ $newHeight = HEIGHT; $newWidth = WIDTH; $newImage = imagecreatetruecolor($newWidth,$newHeight); imagejpeg($newImage,$originalImage,100); } ?> 
  • What do you want to do? You read the file, if the new sizes are larger than the old ones, you create an empty new one with old sizes and (empty) you save it. I guessed? - alexlz
  • I read if the width or height exceeds the norm, I set a new width and height and save it already with the new parameters - quaresma89
  • Thank you right now, I'll try! - quaresma89

1 answer 1

Do you save a blank image? (Nowhere is there any connection with the old jpg.)

See imagecopyresampled.

  • Everything turned out, thank you very much! - quaresma89
  • @Zhenka Sidorov, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - ReinRaus