last update: Mon, 05 Sep 2011 17:21:15 +0000
  1. <?
  2. //create thumbnails
  3. function createthumb($name,$filename,$new_w,$new_h)
  4. {
  5. $system=explode('.',$name);
  6. $src_img = 0;
  7. //echo sizeof($system)."<br />";
  8. //echo "$name<br />";
  9. //echo "size: ".filesize($name)."<br />";
  10. $imagesize = GetImageSize($name);
  11. $realsize = $imagesize[0]*$imagesize[1]*3;
  12. //echo "realsize= $realsize<br />";
  13. if ($realsize < (33554432 / 8))
  14. //if (false)
  15. {
  16. if (preg_match('/jpg|jpeg|JPG/',$system[sizeof($system)-1]))
  17. {
  18. $src_img=@imagecreatefromjpeg($name);
  19. }
  20. if (preg_match('/bmp|BMP/',$system[sizeof($system)-1]))
  21. {
  22. $src_img=@imagecreatefromwbmp($name);
  23. }
  24. if (preg_match('/png|PNG/',$system[sizeof($system)-1]))
  25. {
  26. $src_img=@imagecreatefrompng($name);
  27. }
  28. if (preg_match('/gif|GIF/',$system[sizeof($system)-1]))
  29. {
  30. $src_img=@imagecreatefromgif($name);
  31. }
  32. if ($src_img)
  33. {
  34. $old_x=imageSX($src_img);
  35. $old_y=imageSY($src_img);
  36. if ($old_x > $old_y)
  37. {
  38. $thumb_w=$new_w;
  39. $thumb_h=$old_y*($new_h/$old_x);
  40. }
  41. if ($old_x < $old_y)
  42. {
  43. $thumb_w=$old_x*($new_w/$old_y);
  44. $thumb_h=$new_h;
  45. }
  46. if ($old_x == $old_y)
  47. {
  48. $thumb_w=$new_w;
  49. $thumb_h=$new_h;
  50. }
  51. $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
  52. imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
  53. if (preg_match("/png/",$system[1]))
  54. {
  55. imagepng($dst_img,$filename);
  56. }
  57. if (preg_match("/gif/",$system[1]))
  58. {
  59. imagegif($dst_img,$filename);
  60. }
  61. else
  62. {
  63. imagejpeg($dst_img,$filename);
  64. }
  65. imagedestroy($dst_img);
  66. imagedestroy($src_img);
  67. return true;
  68. }
  69. else {
  70. //echo "could not create image<br />";
  71. }
  72. }
  73. else {
  74. if ($realsize < 5000*5000) {
  75. //echo "image to big ($realsize)<br />";
  76. //echo "./exec/convert -thumbnail ".escapeshellcmd($new_w)." ".escapeshellcmd($name)." ".escapeshellcmd($filename)."<br>";
  77. exec("./exec/convert -thumbnail ".escapeshellcmd($new_w)."x".escapeshellcmd($new_h)." ".escapeshellcmd($name)." ".escapeshellcmd($filename)."");
  78. return true;
  79. }
  80. }
  81. return false;
  82. }
  83. ?>

goto line:
Compare with:
text copy window edit this code post new code