Guest User

Untitled

a guest
Jun 25th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. function resizeImage($file,$scale="",$width="",$height="")
  2. {
  3. // If they wish to scale the image.
  4. if (isset($scale))
  5. {
  6. // Create our image object from the image.
  7. $fullImage = imagecreatefromjpeg($file);
  8. // Get the image size, used in calculations later.
  9. $fullSize = getimagesize($file);
  10. // If there is NOT a thumbnail for this image, make one.
  11. if (!file_exists("tn_".$file))
  12. {
  13. // Create our thumbnail size, so we can resize to this, and save it.
  14. $tnImage = imagecreatetruecolor($fullSize[0]/$scale, $fullSize[1]/$scale);
  15. // Resize the image.
  16. imagecopyresampled($tnImage,$fullImage,0,0,0,0,$fullSize[0]/$scale,$fullSize[1]/$scale,$fullSize[0],$fullSize[1]);
  17. // Create a new image thumbnail.
  18. imagejpeg($tnImage, "tn_".$file);
  19.  
  20. // Clean Up.
  21. imagedestroy($fullImage);
  22. imagedestroy($tnImage);
  23. // Return our new image.
  24. return "tn_".$file;
  25. }
  26. // If there is a thumbnail file, lets just load it.
  27. else
  28. return "tn_".$file;
  29. }
  30. // If they want to force whatever size they want.
  31. elseif (isset($width) && isset($height))
  32. {
  33. return "tn_".$file;
  34. }
  35. else
  36. {
  37. return false;
  38. }
  39. }
Add Comment
Please, Sign In to add comment