Closed Thread Icon

Topic awaiting preservation: php Dynamic image resize to proportion Pages that link to <a href="https://ozoneasylum.com/backlink?for=28753" title="Pages that link to Topic awaiting preservation: php Dynamic image resize to proportion" rel="nofollow" >Topic awaiting preservation: php Dynamic image resize to proportion\

 
Author Thread
CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 12-20-2006 21:10

Was wondering if anyone had a simple way of resizing images on a given page but only if it is over a certain amount.
I have been playing around with some stuff but can't get anything better than having to do something like :

code:
<img src="http://mywebsite/thumb.php?src=image001.jpg&x=200&y=200&f=0" />



The end user wouldn't see anything of course without looking at the source, but I just don't know about doing something like that. There has to be a better way.

Thanks in advance!

Later,

C:\

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 12-21-2006 09:42

Do you mean that you want to process the image file to actually resize it, or that you want to keep the image file the same, and have the browser put size constraints on it?

Either way, I believe you can calculate the aspect ratio like this:

First, decide what the critical parameter is. Do you want to constrain it to a certain width, or to a certain height? On most web pages, this'd be width. So, let's say that, for arguments sake, your image file's original dimensions are 600px wide by 800px high.

ratio = original image height / original image width

So, ratio = 800.0 / 600.0 (the .0 being added because most programming languages make a distinction between 'div' and 'divide'. One being done in whole integer units, the other in floating-point numbers).

ratio = 1.33 (actually 1.33recurring, but we'll whittle it down to that, for arguments sake);

new width = 200px (the constraint width)

new height = 200px * ratio

So, new height = 200 * 1.33 = 266px

And thus you hve new image dimensions that retain the aspect ratio of the original. What you do with this, then, is up to you. I'd honestly not even do this on-the-fly with a PHP script. Do it once, and store the thumbnailed copy of the image somewhere else, and just reuse it in the page.


Justice 4 Pat Richard

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 12-21-2006 13:23

I thought about doing it on the fly but, I think you are right. Just have it uploaded and the same script that uploads it, reads the image size, and makes a thumb nail in a different directory. I could just append the thumb nail so it would be something like, thmb_imageName.jpg. Store the original image name in the database and when I call it from the page, just add the *thmb* part to it.

Thanks for the help. Hugh gave me some stuff last night that I'm going to try to work with as well.

Later,

C:\

iconian
Nervous Wreck (II) Inmate

From: Perth, Western Austrlia
Insane since: Oct 2004

posted posted 01-12-2007 09:08

Hi C:\
I know this is a bit late but...

There is code for a PHP frontend for image magick available here http://www.evolt.org/article/PHP_frontend_to_ImageMagick/17/55650/

using this you can then basically request the image via {serverdetails}/image.php/imagename.jpg?resize(100x150) and this automatically checks to see if the image is cached if not creates at appropriate size based on the query string and displays. It can also do some other cool stuff.

I used this for a photographers website to generate the live thumbnails.

Matthew.

« BackwardsOnwards »

Show Forum Drop Down Menu