Guest User

Untitled

a guest
Jan 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. $file_path = $this->options['upload_dir'].$file_name;
  2. $new_file_path = $options['upload_dir'].$file_name;
  3. list($img_width, $img_height) = @getimagesize($file_path);
  4.  
  5. if (!$img_width || !$img_height) {
  6. return false;
  7. }
  8.  
  9. $scale = min(
  10. $options['max_width'] / $img_width,
  11. $options['max_height'] / $img_height
  12. );
  13.  
  14. if ($scale > 1) {
  15. $scale = 1;
  16. }
  17.  
  18. $new_width = 1280; //$new_width = $img_width * $scale;
  19. $new_height = 323; //$new_height = $img_height * $scale;
  20. $new_img = @imagecreatetruecolor($new_width, $new_height);
  21.  
  22. switch (strtolower(substr(strrchr($file_name, '.'), 1))) {
  23. case 'jpg':
  24. case 'jpeg':
  25. $src_img = @imagecreatefromjpeg($file_path);
  26. $write_image = 'imagejpeg';
  27. break;
  28. case 'gif':
  29. $src_img = @imagecreatefromgif($file_path);
  30. $write_image = 'imagegif';
  31. break;
  32. case 'png':
  33. $src_img = @imagecreatefrompng($file_path);
  34. $write_image = 'imagepng';
  35. break;
  36. default:
  37. $src_img = $image_method = null;
  38. }
  39.  
  40. $success = $src_img && @imagecopyresampled(
  41. $new_img,
  42. $src_img,
  43. 0, 0, 0, 0,
  44. $new_width,
  45. $new_height,
  46. $img_width,
  47. $img_height
  48. ) && $write_image($new_img, $options['upload_dir'] . $_GET['type'] . '.' . strtolower(substr(strrchr($file_name, '.'), 1)), 100);
  49.  
  50. @imagedestroy($src_img);
  51. @imagedestroy($new_img);
  52.  
  53. $success = $src_img && @imagecopyresampled(
  54. $new_img,
  55. $src_img,
  56. 0, 0, 0, 0,
  57. 192,
  58. 50,
  59. $img_width,
  60. $img_height
  61. ) && $write_image($new_img, $options['upload_dir'] . $_GET['type'] . 'THUMB.' . strtolower(substr(strrchr($file_name, '.'), 1)), 100);
  62.  
  63. Bob.jpg 800kb
  64. BobTHUMB.jpg 800kb
  65.  
  66. $thm_img = @imagecreatetruecolor( 192, 50 );
  67.  
  68. $success = $src_img && @imagecopyresampled(
  69. $thm_img,
  70. $src_img,
  71. 0, 0, 0, 0,
  72. 192,
  73. 50,
  74. $img_width,
  75. $img_height
  76. ) && $write_image($thm_img, $options['upload_dir'] . $_GET['type'] . 'THUMB.' . strtolower(substr(strrchr($file_name, '.'), 1)), 100);
Add Comment
Please, Sign In to add comment