Jump to content
  • 0

работа с gd


andychups
 Share

Question

Добрый день!

У меня возникла небольшая проблема в процессе работы с изображениями. Суть, в том, что скрипт собирает изображения из директории, открывает их, изменяет размер, добавляет водяной знак и сохраняет в это же изображение. Вс? работало нормально, но сейчас появилась вот такая проблема:

Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 2376 bytes) in /var/www/site.ru/htdocs/gallery/resizeall.php on line 35

Знающие люди говорят, что это возникает из-за неправильного сжатия JPEG файлов.

Код скрипта:

<?
set_time_limit(0);
include 'api.watermark.php';
$namedir = "/var/www/site.ru/htdocs/gallery/photos/";
//———————————————————->

$images = scandir($namedir);
$count = count($images);
$exclude_dirs = array(".", "..", "index.php",);

for($i=0;$i<=$count;$i++)
{
if (in_array($images[$i], $exclude_dirs)) {unset ($images[$i]);}
}
sort($images);
print_r($images);
$count = count($images);

for ($a=0;$a<=$count;$a++)
{
$imagename = $namedir.$images[$a];
$filename = $imagename;
list($width, $height) = getimagesize($filename);
if (($width > 900) or ($height > 900))
{
$percent = 0.5;

list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;

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

$watermark = new watermark();
$watermark_img_obj = imagecreatefrompng("watermark.png");
$return_img_obj = $watermark->create_watermark($image_p, $watermark_img_obj, 30);

imagejpeg($return_img_obj, $filename, 100);
}
elseif (($width <= 900) and ($height <= 900))
{
list($width, $height) = getimagesize($filename);
$new_width = $width;
$new_height = $height;

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

$watermark = new watermark();
$watermark_img_obj = imagecreatefrompng("watermark.png");
$return_img_obj = $watermark->create_watermark($image_p, $watermark_img_obj, 30);

imagejpeg($return_img_obj, $filename, 100);
}
}

?>

gd

GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.3.4
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled

Как это обойти? Возможно ли?

Заранее благодарен.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy