The best way to do this and keep the same scale is, a quick example of this would be;

$maxWidth = 100;
$maxHeight = 100;

$im = imagecreatefromjpeg( 'path/to/file' );  //This of course would be for a jpeg

$scale = min(100/imagesx( $im ), 100/imagesy($im) );
$newHeight = $scale * imagesy( $im );
$newWidth = $scale * imagesx( $im );

those will give you the new height and width(to scale);



chad qian wrote:
I run php to upload/resize images now.But I have one question:
 
After people upload images, if we want to resize the image,we must maintain the original aspect ratio. This prevents the image from being "stretched" or "squashed".
 
Now people upload two images.And I need to resize these two images
1) "1.jpg" 40*50
2) "2.jpg" 10*20
 
My thought:(size is height and width here)
"1.jpg" or "2.jpg" will be "stretched" or "squashed" if we keep them as same size.
"1.jpg" and "2.jpg" will maintain the original aspect ratio but different size
 
Is it right?
 
Thanks!
 
chad
 


Watch “Cause Effect,” a show about real people making a real difference. Learn more.

_______________________________________________ New York PHP Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to