English 中文(简体)
2. 在不超出记忆限制的情况下,将多个图像转作其他地方
原标题:resize multiple images in php without exceeding memory limit

I am currently trying to get a form which will allow multiple images to be uploaded and resized on the server using PHP. Each uploaded image by the client is around 2.5mb in size.

I am currently using the move_uploaded_file() function.

将档案移至服务器没有任何问题。 当我尝试种植时,问题就会出现。 在我的东道方没有ImageMagick之后,我正在使用这一套办法(并不是所有相关的法典,而是与$width 。 等

$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $output_filename, 80);

目前,这只能用于2个图像。 如果提交了3份或3份以上的材料,我就会出现一个全记错误。 由于我的记忆极限是120mb,我对此进行了研究。 很显然,_imagecreate fromjpeg功能使用了许多记忆,特别是如果档案有一大分辨率(这确实如此),因此我需要加以种植/翻新。

是否有人知道对这项工作采取更高效的办法? 我已经研究过奥古拉,但大家使用我所讲的同样技术。

最佳回答

http://php.net/manual/en/Function.imagedestroy.php。

$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $output_filename, 80);
imagedestroy($image);
imagedestroy($image_p);
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签