Preloading dynamically generated php images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kiq
Forum Newbie
Posts: 9
Joined: Mon Jul 03, 2006 6:52 am

Preloading dynamically generated php images

Post by kiq »

Has anyone got any ideas on preloading images that are dynamically generated by php?

I've written a script that thumbnails images for a shopping cart with associated mouseover images and also overlays an image depending on certain conditions (New item, special offer etc.)and the image code in the html looks something like this

Code: Select all

<a href=\"shopproduct.php?prod=$id\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image $id','','thumbs.php?im=$pic&w=100&h=100&overlay=$overlay',1)\"><img src=\"thumbs.php?im=$mousover_pic&w=100&h=100&overlay=$overlay\" border=\"0\"  name=\"Image $id\" /></a>
So basically I could really do with finding a way to preload the mouseovers. I'm thinking it's maybe not possible because thumbs.php is always called by 'img src=' and hence processes the source img regardless of whether it's cached by the browser or not but if anyone can come up with a solution it would be greatly appreciated.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

You could use the standard (boring, crappy) javascript preload image technique, or you could try some fancy CSS flicker-free rollovers. Google search for the technique if you're interested.

Also, if it's server time your concerned about, you could cache the images.
kiq
Forum Newbie
Posts: 9
Joined: Mon Jul 03, 2006 6:52 am

normal js preloads won't work because.....

Post by kiq »

This is my problem, using a normal javascript to preload these images doesn't work because the image link is :

img src=thumb.php?image=myimage.jpeg

as opposed to:

img src=myimage.jpeg
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Re: normal js preloads won't work because.....

Post by WaldoMonster »

kiq wrote:This is my problem, using a normal javascript to preload these images doesn't work because the image link is :

img src=thumb.php?image=myimage.jpeg

as opposed to:

img src=myimage.jpeg
Most browsers will cache an image when sending a Last-Modified: header.
kiq
Forum Newbie
Posts: 9
Joined: Mon Jul 03, 2006 6:52 am

sorted i think

Post by kiq »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I think i've sorted my problem, i'm just generating the thumbnails at the point of uploading the source image, that should sort the page load time out a bit and allow me to preload the rollovers, it means i have to recreate the thumb everytime the settings for the associated product change to 'new', 'special offer' or 'sold out' but it turns out be easier than i thought. thanks for your replies,
carlos

A cut down version of the code if anyone needs to create a thumbnail of an image they are uploading:

Code: Select all

$source = $_FILES['pic']['tmp_name'];
$dest = "/home/blah/www/mythumbnails/";
$imgname = "". $_FILES['pic']['name']."";
$im = imagecreatefromjpeg($source);
list($width, $height) = getimagesize($source);
$thumb = imagecreatetruecolor(150, 150);
imagecopyresized($thumb, $im, 0, 0, 0, 0, 150, 150, $width, $height);
imagejpeg($thumb, "{$dest}{$imgname}");

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply