simg.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?
  2. // The file
  3. $dir = @$_GET['dir'];
  4. $file = @$_GET['file'];
  5. $filename = $dir . '/'. $file;
  6. if(@$_GET['w']==0) {
  7. $new_width=70;
  8. } else {
  9. $new_width=$_GET['w'];
  10. };
  11. $mini_filename = 'miniatury/' . $dir . '/' . $new_width . '-' . $file;
  12. // Content type
  13. header('Content-type: image/jpeg');
  14. header('Cache-Control: public');
  15. if(!file_exists($mini_filename)){
  16. list($width, $height) = getimagesize($filename);
  17. $new_height=$height*($new_width/$width);
  18. if(!file_exists('miniatury/'.$dir)){
  19. mkdir('miniatury/'.$dir, 0755, true);
  20. }
  21. // Resample
  22. $image_p = imagecreatetruecolor($new_width, $new_height);
  23. if(preg_match('|\.[jJ][pP][eE]?[gG]$|',$filename)){
  24. $image = imagecreatefromjpeg($filename);
  25. } elseif(preg_match('|\.[gG][iI][fF]$|',$filename)){
  26. $image = imagecreatefromgif($filename);
  27. } elseif(preg_match('|\.[pP][nN][gG]$|',$filename)){
  28. $image = imagecreatefrompng($filename);
  29. }
  30. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  31. // Output
  32. //imagejpeg($image_p, null, 70);
  33. if(!file_exists('miniatury/'.$dir)){
  34. mkdir('miniatury/'.$dir, 0755, true);
  35. }
  36. imagejpeg($image_p, $mini_filename, 70);
  37. }
  38. echo file_get_contents($mini_filename);
  39. ?>