How do I auto resize user's inputted images to a specific dimension in PHP?

前端 未结 5 1598
走了就别回头了
走了就别回头了 2021-01-14 16:17

When users input their images, their images are any size. I want to be able to resize all the images to a specific dimension. Is there a function that allows me to do that i

相关标签:
5条回答
  • 2021-01-14 16:42

    Here's a very good library that you can resize images with. It has ways to resize them so they are still proportionate and it has options to save, or display images as well. Works really slick

    http://phpthumb.gxdlabs.com/

    0 讨论(0)
  • 2021-01-14 16:44

    http://php.net/gd

    Specifically, http://php.net/imagecopyresized

    0 讨论(0)
  • 2021-01-14 16:50

    Try ImageMagick, it keeps the EXIF information in an image if it needs it, among other things:

    http://php.net/manual/en/book.imagick.php

    0 讨论(0)
  • 2021-01-14 16:51

    The function you need is imagecopyresampled, that also interpolate pixels, (imagecopyresized does not);
    In my code I use a it in a function like this:

    function resizeAndSavePhoto($original, $destination, $dest_width, $dest_height){    
        $photo = createImage($original);
        $size =  getimagesize($original);
    
        $final_photo = imagecreatetruecolor($dest_width, $dest_height);
    
        imagecopyresampled($final_photo, $photo,0,0,0,0,$dest_width, $dest_height, $size[0], $size[1]);
        imagejpeg($final_photo, $destination, 100);
    }
    

    $orignal and $destination are filename paths

    0 讨论(0)
  • 2021-01-14 16:56

    ok you can make something:

    http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/

    or use something already made, i use this one:

    http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php which works a treat

    0 讨论(0)
提交回复
热议问题