Resize image on server

后端 未结 3 1312
执笔经年
执笔经年 2020-12-20 10:10

I made a file that is in charge of uploading images, this images are then moved to a folder in the server. I think I can\'t resize the image directly in the $_FILES array so

3条回答
  •  一向
    一向 (楼主)
    2020-12-20 11:12

    I wasn't creating a file to the server's dir so this is what I did move_uploaded_file($_FILES[$str]['tmp_name'], $target); scale_image($target,$target);

    Now the function scale_image()

    function scale_image($image,$target)
    {
      if(!empty($image)) //the image to be uploaded is a JPG I already checked this
      {
         $source_image = imagecreatefromjpeg($image);
         $source_imagex = imagesx($source_image);
         $source_imagey = imagesy($source_image);
    
         $dest_imagex = 300;
         $dest_imagey = 200;
    
         $image2 = imagecreatetruecolor($dest_imagex, $dest_imagey);
         imagecopyresampled($image2, $source_image, 0, 0, 0, 0,
         $dest_imagex, $dest_imagey, $source_imagex, $source_imagey);
    
         imagejpeg($image2, $target, 100);
    
      }
    }
    

    Thank you all very much, the resource you gave me helped me to create this function.

提交回复
热议问题