Posted By

dmlanger on 01/21/08


Tagged

resize image size Restrain


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

skywalker
mbcdg
uisluu
haozi


Image Size Restrainer


 / Published in: PHP
 

This function will return the height and width of an image that will change if the height/width is greater than the maximum supplied width and height.

  1. function sizeme($img){
  2. $maxx=400;
  3. $maxy=300;
  4. list($width,$height)=getimagesize($img);
  5. if($width>$maxx){
  6. $newwidth = $maxx;
  7. $newheight = round($newwidth/$width*$height);
  8. } else {
  9. $newwidth=$width;
  10. $newheight=$height;
  11. }
  12. if($newheight>$maxy){
  13. $newheight1=$maxy;
  14. $newwidth1=round($newheight1/$newheight*$newwidth);
  15. } else {
  16. $newheight1=$newheight;
  17. $newwidth1=$newwidth;
  18. }
  19. $out=array('width'=>$newwidth1,"height"=>$newheight1);
  20. return $out;
  21. }

Report this snippet  

You need to login to post a comment.