RE: RE: Coding Help

From: Date: Wed, 18 Oct 2000 18:23:46 +0000
Subject: RE: RE: Coding Help
Groups: php.general 
Request: Send a blank email to php-general+get-20951@lists.php.net to get a copy of this message
Hi Marc - thanks for the reply. Yeah, I know about fake resize - but what I'm talking about is giving users the ability to upload a photo (it's for a personals site), and then not only making a thumbnail copy, (I could even use some of the code I've found in the ever so handy "Professional PHP Programming" tome, but also resizing the original photo. Given that these photos will be taking up disk space, I'd like to set maximums on the dimensions, and if the photo is over these, to resize it. I know that I can limit the file size, etc. - and the way I'm currently doing it is checking the uploaded image dimensions and bouncing to an error page if they are out of range. I guess what I'm really after is a mathematical (probably geometrical, actually) algorithm that is currently escaping me. To wit: Give an photo of n x n, how to resize to say, 300 pixels high (or under) while maintaining the aspect ratio of the original photo. This same algorithm would work with both the full size and thumbnail photo. In order to do this with the Image functions in PHP, my understanding is that you need to use a function like imageCreateFromJPG() or whatever. But because no two uploaded photos will be the same size, I just need to get output <= my max dimensions . . . . It's just figuring out how to size the output that's got me stumped . . . I guess there were too many bong hits before Algebra Class lo those many years ago (or maybe not enough?). . . . . . . . LOL At 05:52 AM 10/18/00 -0400, you wrote: Does anyone have a generalize algorithm for making thumbnails out of a photo of unkown size? That is, I'm not going to know the dimensions of the source photo beforehand, and what I'd like to do is to reduce the photo to about 60-80 pixels high, depending on the aspect ratio . . . . Any tips would be greatly appreciated. =)) (1) If you mean a 'fake' resize (simply giving the image tag fake width and height measurements and letting the browser crush it down): Note the getimagesize() function. Among other things, it returns to you the width and height of the image. You can simply pick a fixed width and fixed height you'd like to work with. Say, 80 and 80. Read both the width and height and check which is higher. Then divide the other one by the longer and multiply it by 80. Then, simply spit out the image tag with 80 in the longer of width and height, and the integer returned in the shorter one. (2) If you mean a 'real' resize (actually saving another copy of the image, in order to save the user download time when looking at thumbnails): In PHP, I don't know. We generally create all our images on Macs, and so we automate this process in Photoshop using PhotoScripter and AppleScripts. Then the files are copied to the Web server over AppleTalk. You would be able to accomplish it in PHP, perhaps with the GD library or ImageMagick, though. Anyone else? Cheers, -- Marc Antony Vose http://www.suzerain.com/ Into every tidy scheme for arranging the pattern of human life, it is necessary to inject a certain dose of anarchism. -- Bertrand Russell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#20951) next »