Php image resize function

I HOPE YOU ARE ALL FINE)

In my web i`m using image magic or GD library to resize photos when someone upload them to the server.
This makes me create alot of thumbnails for a single photo.

So i`m asking if their is any function in PHP which can resize photo when displaying.
i mean,i will upload the original photo without resize and when displaying it,i will use that function to resize to any size i want.

ANY SUGGESTIONS WILL BE APPRECIATED.

Short answer: no. Create a thumbnail for every picture that is uploaded immediately.

Long answer: yes. However then a thumbnail needs to be generated for every request, and it will slow your response times.

Hard disk space is cheap, so the slowness is worse than the cost of storing thumbnails.

I have just been trying this with ImageMagick and displaying the results on the fly were:
0.5-0.6 seconds per image on one server using 26% cpu
2.8 seconds per image on another server using 99% cpu

I do not know the best way around this as I was looking at about 8,000 images on the server which could be about 800Mb space used.

The Image Magick code you could try:


$input_image = "input.jpg";
$width = "100";
$height = "100";
$cmd = "convert $input_image -resize {$width}x{$height} jpg:-";
header("Content-type: image/jpeg");
passthru($cmd, $retval);

//This code must be on a page of its own and called by < img src="resize.php" >

So as i understand from @alienDev and @rubble speed must be the problem))

@rubble thankx for the links.

i guess i need to continue with creating thumbnails as i was doing.

I was not thinking straight last night the code above was creating the image using a shell script and doing a lot more than resizing.

Some times comparisons for resizing and saving to disc here: Image magick, imagick, gd speed test

I do not have access to the two servers I posted the results above now and can not check the cpu usage. I would recomend having a go and see what results you get.