• Notice regarding image hosts and attachments. See here.

Resize image on fly?

Associate
Joined
18 Oct 2002
Posts
2,092
Location
Edinburgh
im trying to resize images on the fly, is it possible?

i got hold of the image resize function which gives a file handle but is it possible to now display this?

PHP:
function resize_jpg($inputFilename, $new_side){	
$imagedata = getimagesize($inputFilename);
	$w = $imagedata[0];	$h = $imagedata[1];
		if ($h > $w) {		$new_w = ($new_side / $h) * $w;
		$new_h = $new_side;		} else {
		$new_h = ($new_side / $w) * $h;		$new_w = $new_side;
	}		$im2 = ImageCreateTrueColor($new_w, $new_h);
	$image = ImageCreateFromJpeg($inputFilename);
	imagecopyResampled ($im2, $image, 0, 0, 0, 0, $new_w, $new_h, $imagedata[0], $imagedata[1]);
	return $im2;}
 
EDIT: lol, looks like i have totally the wrong end of the stick again. :/




totally hazzarding a guess but:

Code:
readfile($im2);

I am not sure but that function may require the filename. So you may have to do it like this:

Code:
readfile($inputFilename);
 
Last edited:
using the original filename would be no help as the function resizes the image and stores it in memory.
im not sure the other function would work either as i need to display it in the middle of a page
 
Yeah looks like i have the wrong end of the stick again.

What are you actually doing and it would help (well me) to post the right thing.
 
im basically taking images from a larger photo gallery and using them in posts on my blog script, i don't want the images to be too large and the images change often so i don't really want to save it, there won't be many images on each page, max prob about 6
 
Would it not be best to temporary save them rather than do it on the fly?

As if you have a lot of people visiting the site, it will use a lot of memory or processing power....lol i don't know which one as i am a newbie at php, but i know its bad.
 
Just save them permanently as $filename-thumb.$extension or something. You really don't want to be doing this every page load, it will kill your server in about 5 seconds and probably get your hosting cancelled (I presume you're on shared hosting).
 
is this not how the likes of gallery 2 work?? gallery 1 used to save the image thumbnails, gallery 2 does it on the fly.
 
Gallery2 must cache them - or at least have the option. It can also cache entire pages, too - kinda useful for 400k page impressions/day like one Gallery I host :D
 
well i sorted it now thanks, turns out my glob function wasn't quite right giving a slightly wrong filename
 
Back
Top Bottom