开发者

PHP image resizing not working. Is there a file size limit?

I'm using a simple image manager class, and the following code:

<?php
include('SimpleImage.php');
$image = new SimpleIma开发者_开发问答ge();
$image->load($target_path);
if($image->getWidth() > 500) {
    $image->resizeToWidth(500);
    echo "<p>Image Resized</p>";
} else echo "<p>Image did not need to be resized.</p>";
$image->save($target_path);
echo "<p>Image Saved</p>";
?>

The image is successfully resized when I upload an image with a width of 700, but when I upload a really big picture (width ~= 2300), it doesn't work, and I don't see any of my echo messages.

Do certain php image functions have a size limit that might be causing this?


You are most likely hitting the memory_limit setting specified in php.ini.

Add error_reporting(E_ALL); to your script and see what the output is.

Use phpinfo() to find out the current memory limit setting.

It can sometimes be changed using ini_set("memory_limit", xyz). Otherwise, you need to change php.ini.

A 2300 x 2300 Pixel image is going to take up at least

2300 x 2300 x 3 = 15,870,000

= roughly 16 Megabytes of RAM (or 2300 x 2300 x 4 if there's an alpha channel) so I'd say you would need at least 24 Megabytes of RAM per script to make this work well. Maybe even more.


Check your error log. The chances are that you're exceeding the memory limit (memory_limit in the ini settings). Try adding ini_set('memory_limit', '32M'); to the top of the file.

And to directly answer your question, no there is no size limit on the internal functions...


There is an upload file size limit ; you can to set it in your php.ini :

upload_max_filesize
post_max_size
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜