Posted By

luman on 08/03/06


Tagged

image thumbnails


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

hxseven
visualAesthetic
vali29
hudge


create thumbs


 / Published in: PHP
 

  1. function createthumb($name,$filename,$new_w,$new_h,$type){
  2. $system=explode('.',$name);
  3. if ($type == "jpg" || $type == "jpeg"){
  4. $src_img=imagecreatefromjpeg($name);
  5. }
  6. if ($type == "png"){
  7. $src_img=imagecreatefrompng($name);
  8. }
  9. if ($type == "gif"){
  10. $src_img=imagecreatefromgif($name);
  11. }
  12. $old_x=imageSX($src_img);
  13. $old_y=imageSY($src_img);
  14. if ($old_x > $old_y) {
  15. $thumb_w=$new_w;
  16. $percent = ($new_w * 100) / $old_x;
  17. $thumb_h = ($percent * $old_y) / 100;
  18. }
  19. if ($old_x < $old_y) {
  20. $percent = ($new_h * 100) / $old_y;
  21. $thumb_w = ($percent * $old_x) / 100;
  22. $thumb_h=$new_h;
  23. }
  24. if ($old_x == $old_y) {
  25. $thumb_w=$new_w;
  26. $thumb_h=$new_h;
  27. }
  28. $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
  29. imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
  30.  
  31. if ($type == "png")
  32. {
  33. imagepng($dst_img,$filename);
  34. }
  35. if ($type == "gif")
  36. {
  37. imagegif($dst_img,$filename);
  38. }
  39. if ($type == "jpg" || $type == "jpeg")
  40. {
  41. imagejpeg($dst_img,$filename);
  42. }
  43. imagedestroy($dst_img);
  44. imagedestroy($src_img);
  45. }

Report this snippet  

You need to login to post a comment.