PHP upload and resize image

前端 未结 4 930
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 02:18

I am working on a script that uploads a picture using PHP and I wanna make it resize the image to width 180 before saving it.
I tried using the WideImage library and -

4条回答
  •  天命终不由人
    2020-12-04 02:34

    You don't even need to use the WideImage library.

    Check this script here: http://bgallz.org/502/php-upload-resize-image/

    You start by uploading the image and saving to a temp image file. This script runs off a form with inputs for the max height or max width. So it will then generate a new image file based on the new width/height and then copy the temp image onto the new one created on the server.

    You see this with the following code:

    // Create temporary image file.
    $tmp = imagecreatetruecolor($newwidth,$newheight);
    // Copy the image to one with the new width and height.
    imagecopyresampled($tmp,$image,0,0,0,0,$newwidth,$newheight,$width,$height);
    

提交回复
热议问题