Resize image in PHP

前端 未结 13 1634
长情又很酷
长情又很酷 2020-11-22 04:18

I\'m wanting to write some PHP code which automatically resizes any image uploaded via a form to 147x147px, but I have no idea how to go about it (I\'m a relative PHP novice

相关标签:
13条回答
  • 2020-11-22 04:59

    I would suggest an easy way:

    function resize($file, $width, $height) {
        switch(pathinfo($file)['extension']) {
            case "png": return imagepng(imagescale(imagecreatefrompng($file), $width, $height), $file);
            case "gif": return imagegif(imagescale(imagecreatefromgif($file), $width, $height), $file);
            default : return imagejpeg(imagescale(imagecreatefromjpeg($file), $width, $height), $file);
        }
    }
    
    0 讨论(0)
提交回复
热议问题