PHP Save Image After imagecopyresampled

后端 未结 6 2256
执笔经年
执笔经年 2021-02-19 16:14
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_heig         


        
6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-19 16:37

    To save the image to a file, you can use any of these: imagejpeg(), imagepng(), or imagegif(), depending on your desired output format.

    To detect the image type, you can just check the file's extension and base yourself on that. However, sometimes people manually change the extension of an image file, thinking that actually changes the image type, so it's always a good idea to check whether imagecreatefrom returned an image resource rather than false.

    For a quick way to return just the extension of a file:

    $ext = pathinfo($path_to_file, PATHINFO_EXTENSION);
    

    Manual entry on pathinfo()

提交回复
热议问题