保存图像使用PHP调整大小
发布时间:2020-12-13 22:01:20 所属栏目:PHP教程 来源:网络整理
导读:我正在努力改进我的Facebook应用程序.我需要能够调整图像大小,然后将其保存到服务器上的目录中.这是我要调整大小的代码: ?php// The file$filename = 'test.jpg';$percent = 0.5;// Content typeheader('Content-type: image/jpeg');// Get new dimensionsl
我正在努力改进我的Facebook应用程序.我需要能够调整图像大小,然后将其保存到服务器上的目录中.这是我要调整大小的代码:
<?php // The file $filename = 'test.jpg'; $percent = 0.5; // Content type header('Content-type: image/jpeg'); // Get new dimensions list($width,$height) = getimagesize($filename); $new_width = $width * $percent; $new_height = $height * $percent; // Resample $image_p = imagecreatetruecolor($new_width,$new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p,$image,$new_width,$new_height,$width,$height); // Output imagejpeg($image_p,null,100); ?> 我的问题是,如何保存这个已调整大小的图像?我需要吗?有没有办法操纵调整大小的图像而不保存它? 解决方法
根据
manual on imagejpeg(),可选的第二个参数可以指定要写入的文件名.
将结果写入磁盘以进行一些基本缓存通常是个好主意,这样每次传入的请求都不会导致(资源密集型)GD调用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |