views:

100

answers:

1

I'm working on an image resize script for php, and had a few questions..

Currently I'm pulling an external URL as the image, and don't really want to store the new image that is going to be re-sized on my server. Here is what I'm trying to do:

Have the script resize the image, than encode it the resized image in base64 on the fly. Now what I'm wondering is, would this be heavy on performance both doing the encode, and serving up the image with base64 rather than just the url? or would it be better to store the image rather than to store the base64 code for it?

Thanks in advance

A: 

Why are you encoding the resized image? Why not just output it directly. You don't need to save it to a file.

Some relevant lines from php function page:

// Content type
header('Content-type: image/jpeg');

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);

To include it in the page you would do something like:

<img src="resizer.php?url=[encoded url here]" />
Keith Bentrup
Thanks for this, can i take and echo back the imagejpeg then from another page? so i create a function that sends me back a link? I'm a little confused how by setting the header content type of the page will let me pass the image back to another page?
Frederico
The PHP code above will output a resized jpeg to the browser. When the browser makes the request for the image, in the HTML above, it will get that resized jpeg. This has the effect of displaying the resized image on the page with the <img> tag.
dmertl