PDA

View Full Version : script way slow anyway to speed things up


davehaz
04-18-2006, 06:33 PM
howdy,
I have written a little script to resize images it really slows the page down when loading. Would you experts please take a look at it and let me know if there is anyway to speed it up?


$src=$IMAGEURL;
$typepos = strrpos($src,".");
$typepos++;
$type = substr($src,$typepos);
if($type == 'jpeg'){$src_img=imagecreatefromjpeg($src);}
elseif($type == 'jpg'){$src_img=imagecreatefromjpeg($src);}
elseif($type == 'gif'){$src_img=imagecreatefromgif($src);}
$old_x=imagesx($src_img);
$old_y=imagesy($src_img);
if ($old_x > '150')
{
$thumb_w=$old_x*(150/$old_x);
$thumb_y=$old_y*(150/$old_y);
$width = $thumb_w;
$height = $thumb_y;
}
elseif (($old_x == $old_y) & ($old_x > 150))
{
$width = 150;
$height = 150;
}
elseif ($old_x < '150')
{
$width=$old_x;
$height=$old_y;
}


tia.

fci
04-18-2006, 06:52 PM
how big are the image(s) you are resizing...?

davehaz
04-18-2006, 06:59 PM
the largest I have ran across is 580 X 464. or did you mean filesize?

fci
04-18-2006, 07:16 PM
both sizes..

davehaz
04-18-2006, 07:41 PM
464w X 580h filesize=788K
there are about 10 of these on each page.

thanks for any ideas.

fci
04-18-2006, 08:23 PM
could you be caching the images?

cdwhalley.com
04-18-2006, 08:29 PM
I think it is the image functions that are slowing that down - the rest looks as fast as it could be. So, I think that the long loading times are inevitable.

davehaz
04-18-2006, 09:11 PM
caching-do you mean with the browser? if you are talking about php or system caching I don't know, could you tell me how to check?

fci
04-18-2006, 09:20 PM
no, caching the actual file, for the images that are resized, are those same images resized when the page loads.. ? and, due to the size of those images, you can't really speed it up..
caching basically means saving the resized image as a temporary file and linking to the now already resized image..

davehaz
04-18-2006, 09:26 PM
no, I am really not creating a file or an image as I am not running imagejpeg,
what I am really doing here is using the script above to determine the new width & height values and then I use them in my html such as:

<img src='$Image_Link' alt='$Item, offered by $Buy_Site, $ $Price' border='0' width='$width' height='$height' >

I have no interest in saving the files to my local site. after saying that I realize if I did it would certainly speed things up.

hmmmm

fci
04-19-2006, 01:06 PM
oh.. well, that explains it then, changing the height/width in the HTML will just resize the 788K file to a smaller size.. so, you need to resize the images by generating a *real* thumbnail instead of what you are doing.