fork download
  1. <?php
  2.  
  3. function createThumb($fname, $thumbWidth, $thumbHeight){
  4. $dir = scandir('images');
  5.  
  6. if(!in_array($fname, $dir)){
  7. echo "Ошибка. Изображения не существует $fname";
  8. }
  9. else{
  10. $info = pathinfo("images/$fname");
  11. if(strtolower($info['extension']=='jpg')){
  12.  
  13. $img = imagecreatefromjpeg("images/$fname");
  14. $width = imagesx($img);
  15. $height = imagesy($img);
  16. if($width<$thumbWidth && $height<$thumbHeight){
  17. continue;
  18. }
  19. if($width>$height){
  20. $new_width = $thumbWidth;
  21. $new_height=floor($height*($thumbWidth/$width));
  22. }
  23.  
  24. else{
  25. $new_height = $thumbHeight;
  26. $new_width = floor($width*($thumbHeight/$height));
  27. }
  28.  
  29.  
  30.  
  31. $tmp_img = imagecreatetruecolor($new_width, $new_height);
  32. imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  33. header('Content-Type: image/jpg');
  34. imagejpeg($tmp_img, "thumbnails/$fname");
  35. }
  36.  
  37. elseif(strtolower($info['extension']=='png')){
  38.  
  39. $img = imagecreatefrompng("images/$fname");
  40. $width = imagesx($img);
  41. $height = imagesy($img);
  42. if($width<$thumbWidth && $height<$thumbHeight){
  43. continue;
  44. }
  45. if($width>$height){
  46. $new_width = $thumbWidth;
  47. $new_height=floor($height*($thumbWidth/$width));
  48. }
  49.  
  50. else{
  51. $new_height = $thumbHeight;
  52. $new_width = floor($width*($thumbHeight/$height));
  53. }
  54. $tmp_img = imagecreatetruecolor($new_width, $new_height);
  55. imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  56. header('Content-Type: image/png');
  57. imagepng($tmp_img, "thumbnails/$fname");
  58. }
  59. }
  60. }
  61.  
  62. $fname = $_GET['fname'];
  63. createThumb($fname, 100, 100);
  64.  
Success #stdin #stdout #stderr 0.02s 24448KB
stdin
Standard input is empty
stdout
Ошибка. Изображения не существует 
stderr
PHP Notice:  Undefined index: fname in /home/jnuV5f/prog.php on line 62
PHP Warning:  scandir(images): failed to open dir: No such file or directory in /home/jnuV5f/prog.php on line 4
PHP Warning:  scandir(): (errno 2): No such file or directory in /home/jnuV5f/prog.php on line 4
PHP Warning:  in_array() expects parameter 2 to be array, boolean given in /home/jnuV5f/prog.php on line 6