Guest User

Untitled

a guest
Jan 23rd, 2017
85
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function createThumbnail($filename, $filename_thumb, $factor) {
  2. if (file_exists ($filename_thumb)) {
  3. if (filemtime($filename) > filemtime($filename_thumb)) $create = TRUE; else $create = FALSE;
  4. } else $create = TRUE;
  5. if ($create) {
  6. $info = getimagesize($filename);
  7. switch ($info[2]) {
  8. case IMAGETYPE_JPEG:
  9. $image = imagecreatefromjpeg($filename);
  10. break;
  11. case IMAGETYPE_PNG:
  12. $image = imagecreatefrompng($filename);
  13. break;
  14. case IMAGETYPE_GIF:
  15. $image = imagecreatefromgif($filename);
  16. break;
  17. default: return;
  18. }
  19. $width_th = intval($info[0] * $factor);
  20. $height_th = intval($info[1] * $factor);
  21. $imageth = imagecreatetruecolor($width_th, $height_th);
  22. imagecopyresampled($imageth, $image, 0, 0, 0, 0,
  23. $width_th, $height_th, $info[0], $info[1]);
  24. imagejpeg($imageth, $filename_thumb, 100);
  25. }
  26. }
RAW Paste Data