php resize image on upload

后端 未结 12 1474
别跟我提以往
别跟我提以往 2020-11-27 04:09

I got a form where the user is inserting some data and also uploading an image.

To deal with the image, I got the following code:

define(\"MAX_SIZE\"         


        
12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 04:23

    If you want to use Imagick out of the box (included with most PHP distributions), it's as easy as...

    $image = new Imagick();
    $image_filehandle = fopen('some/file.jpg', 'a+');
    $image->readImageFile($image_filehandle);
    
    $image->scaleImage(100,200,FALSE);
    
    $image_icon_filehandle = fopen('some/file-icon.jpg', 'a+');
    $image->writeImageFile($image_icon_filehandle);
    

    You will probably want to calculate width and height more dynamically based on the original image. You can get an image's current width and height, using the above example, with $image->getImageHeight(); and $image->getImageWidth();

提交回复
热议问题