Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
保存用PHP调整大小的图像_Php_Image_Resize_Save_Editing - Fatal编程技术网

保存用PHP调整大小的图像

保存用PHP调整大小的图像,php,image,resize,save,editing,Php,Image,Resize,Save,Editing,我正在努力改进我的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); $

我正在努力改进我的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, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Output
imagejpeg($image_p, null, 100);
?>

我的问题是,如何保存此调整大小的图像?我需要吗?是否有一种方法可以操作调整大小的图像而不保存它?

根据,可选的第二个参数可以指定一个文件名,该文件名将被写入

文件名

保存文件的路径。如果未设置或为空,则直接输出原始图像流

要跳过此参数以提供质量参数,请使用NULL

将结果写入磁盘进行一些基本缓存通常是一个好主意,这样不是每个传入的请求都会导致(资源密集型)GD调用。


应该是工作

我不明白最后一句话?好的,太好了。我唯一不喜欢的是它确实会显示出来。我决定在背景中调整图像的大小会更好。有没有办法强迫它只保存调整大小的图像,而不显示输出?@Zachary我不明白
$image\u p
已经是调整大小的图像了,不是吗?是的,但我不想显示调整大小的图像,只想保存。这可能吗?@Zachary是的,通过如上所述指定文件名。这里面少了什么?
function resize($img){
/*
only if you script on another folder get the file name
$r =explode("/",$img);
$name=end($r);
*/
//new folder
$vdir_upload = "where u want to move";
list($width_orig, $height_orig) = getimagesize($img);
//ne size
$dst_width = 110;
$dst_height = ($dst_width/$width_orig)*$height_orig;
$im = imagecreatetruecolor($dst_width,$dst_height);
$image = imagecreatefromjpeg($img);
imagecopyresampled($im, $image, 0, 0, 0, 0, $dst_width, $dst_height, $width_orig, $height_orig);
//modive the name as u need
imagejpeg($im,$vdir_upload . "small_" . $name);
//save memory
imagedestroy($im);
}