PHP在imagecopy重新采样后保存图像 [英] PHP Save Image After imagecopyresampled

查看:39
本文介绍了PHP在imagecopy重新采样后保存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

如何将调整大小后的图像保存到folder/中? 以及如何检测图像类型为jpg/png/gif?

How can i save the resized image to folder/ ? And how can I detect the image type is jpg/png/gif?

推荐答案

要将图像保存到文件中,可以使用以下任意一种方法: imagepng( ),或 imagegif(),具体取决于您所需的输出格式

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

要检测图像类型,您只需检查文件的扩展名并以此为基础即可.但是,有时人们会手动更改图像文件的扩展名,以为实际上会更改图像类型,因此,检查imagecreatefrom是否返回图像资源而不是false始终是一个好主意.

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);

在pathinfo()上手动输入

这篇关于PHP在imagecopy重新采样后保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆