473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem resizing multiple images

I'm using the code below to loop through some images and resize each image
twice, once to create a thumbnail and once to create a small image.

The page stops loading around the 38th image out of 40+. Not always the same
place but it's either 38th or 39th image, which I find strange as it's not
consistent.

At first I thought it was a timeout problem so I added - set_time_limit(0);
and ignore_user_abort (true); to prevent it timing out, there was no
'connection timeout' error or similar, there have been no printed errors.

I've tried running the same loop but commenting out one of the resize
functions, when I do this the page completes and all the images are resized
correctly, then I comment out the other resize function and again that
worked, so I don't believe that there is a problem with the images.

Which leaves a memory problem. In the function that resizes the image
(included below) I have used ImageDestroy to get rid of the two images from
memory.

Can anyone see what is going wrong or give me any pointers? Thanks
Alex
while ($row = mysql_fetch_row($imagestoprocess)) {
$counter++;
echo $counter."<br>";
// sleep(3);
$imagename = $row[33]; //get name of main image
$imagelocation = $salessourceimagedir[$_GET['office']]."/".$imagename;
//work out image name and path
//echo "im:-".$imagelocation."-";
$imagedestination = $salesimagedir."/".$imagename; //work out image name
and path
if (file_exists($imagelocation)) { //see if file exists
$thumbdestination = $salesimagedir."/thumb".$imagename; //work out image
name and path
echo "<br>resizing ".$imagelocation." to ".$imagedestination;
resizejpeg
($imagelocation,$imagedestination,$proplargeimageh ,$proplargeimagew,'70','0');
echo " done<br>resizing ".$imagedestination." to ".$thumbdestination;
resizejpeg
($imagedestination,$thumbdestination,$propthumbima geh,$propthumbimagew,'70','0');
echo " done<br>";
}

function resizejpeg($image,$newimage,$max_height,$max_width ,$image_quality){
/* $image = "/home/web/images/original.jpg";
$newimage = "/home/web/images/new.jpg";
$image_quality = 80;
$addborder = 1;
$max_height = 200;
$max_width = 300;
*/
// Main code
echo "aa";
$src_img = ImageCreateFromJpeg($image);
$orig_x = ImageSX($src_img);
$orig_y = ImageSY($src_img);
echo "a";
$new_y = $max_height;
$new_x = $orig_x/($orig_y/$max_height);
echo "b";

if ($new_x > $max_width) {
$new_x = $max_width;
$new_y = $orig_y/($orig_x/$max_width);
}
echo "c";

$dst_img = ImageCreateTrueColor($new_x,$new_y);
ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $new_x, $new_y, $orig_x,
$orig_y);
/*
if ($addborder == 1) {
// Add border
$black = ImageColorAllocate($dst_img, 0, 0, 0);
ImageSetThickness($dst_img, 1);
ImageLine($dst_img, 0, 0, $new_x, 0, $black);
ImageLine($dst_img, 0, 0, 0, $new_y, $black);
ImageLine($dst_img, $new_x-1, 0, $new_x-1, $new_y, $black);
ImageLine($dst_img, 0, $new_y-1, $new_x, $new_y-1, $black);
}
*/
echo "d";
ImageJpeg($dst_img, $newimage, $image_quality);
ImageDestroy($src_img);
ImageDestroy($dst_img);
echo "e";

}

Jul 17 '05 #1
2 2670
NC
Alex Hopson wrote:

I'm using the code below to loop through some images and resize each image twice, once to create a thumbnail and once to create a small image.

The page stops loading around the 38th image out of 40+. Not always the same place but it's either 38th or 39th image, which I find strange as it's not consistent.

At first I thought it was a timeout problem so I added - set_time_limit(0); and ignore_user_abort (true); to prevent it timing out, there was no
'connection timeout' error or similar, there have been no printed

errors.

The combination of low-level error reporting and running PHP in the
safe mode can produce the same effect. set_time_limit() has no effect
when PHP is running in safe mode. Low-level error reporting can
suppress the error message, so the script will time out without you
knowing it.

Also, your HTTP server may be imposing an execution time limit.
Apache, for example, has a configuration directive called Timeout.
Try running your script from the command line. If it completes,
the problem obviously lies with the HTTP server.

Cheers,
NC

Jul 17 '05 #2
I recently had a similar problem.

I had to resize a large number of images using imagemagick.
While the initial image size was about 140Mb, each resize operation
took at least 6-10 secs.

I partialy solved the problem of timeout by redirecting to the same
script [ Header("Location: ...") ], after every 5 or 6 resizes.

But that approch produces another problem:
The script stopped redirecting after 20 or so times and produced a
"Javascript-alert-type" message box informing that the maximum number
of redirects was reached. I initialy thought that was a web browser
setting but i could not come across a way to change it. (By the way,
the message was produced while using either Firefox or IE)

Depending on the number of images you are resizing each time, my
solution might work for you, thought I have no clue concerning tha
redirect limit problem.
Vasilis

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: lawrence | last post by:
Can someone please tell me where I can get some open source code for resizing images? I know such code has been written a million times and I don't feel like doing it again from scratch.
10
by: riki | last post by:
Hi, i have a big problem...i'm using one jscript for resizing of all of my pics in popUp...in main html i'm having many little pics and clicking on them they open in popUp and resize to larger...
5
by: Jim | last post by:
I've heard that resizing images through PHP (either GD2 or ImageMagick) is a processor intensive exercise. I'm setting up a site where users will be uploading up to 10 images along with the details...
0
by: E | last post by:
I wrote code which Resizes images and then saves them below is the 2 methods. The problem is that half of the resized image turns out gray, as if it wasn't completed. Could someone please tell me...
1
by: Ron Vecchi | last post by:
I am using asp.net to upload an image and then perform resizing on it and saving the different sizes to file. The resized images were coming up and being displayed in the bowser fine but the image...
3
by: Pitcairnia | last post by:
The basic purpose of the site is for authenticated users to post event listings, which often include photographs. The user is faced with a page where they can insert all of the information about...
0
by: Brian Henry | last post by:
Ok whats going on here... got a couple problems... this is relevant now to this group since .NET 2.0 is finally RTM 1) draws really slow when making it a large form (resizing speed is jerky) to...
3
by: reachmano | last post by:
Hello everyone: When I view my web-page on different computers, I am having trouble with re-sizing the screen on some of them. Was wondering what should be done differently to take care of the...
3
by: vozzek | last post by:
Hi all, I'm a CSS rookie, but I'm stumped. Hopefully this is something simple that I'm overlooking. My master/detail page generates the following html code, and I've got it formatted with CSS...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.