Guest User

Untitled

a guest
Jan 22nd, 2017
135
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. function createThumbnail($filename, $filename_thumb, $factor) {
  3. if (file_exists ($filename_thumb)) $create = FALSE; else $create = TRUE;
  4. if ($create) {
  5. $info = getimagesize($filename);
  6. switch ($info[2]) {
  7. case IMAGETYPE_JPEG:
  8. $image = imagecreatefromjpeg($filename);
  9. break;
  10. case IMAGETYPE_PNG:
  11. $image = imagecreatefrompng($filename);
  12. break;
  13. case IMAGETYPE_GIF:
  14. $image = imagecreatefromgif($filename);
  15. break;
  16. default: return;
  17. }
  18. $width_th = intval($info[0] * $factor);
  19. $height_th = intval($info[1] * $factor);
  20. $imageth = imagecreatetruecolor($width_th, $height_th);
  21. imagecopyresampled($imageth, $image, 0, 0, 0, 0,
  22. $width_th, $height_th, $info[0], $info[1]);
  23. imagejpeg($imageth, $filename_thumb, 100);
  24. }
  25. }
  26. $filename = 'images/dia0.jpg';
  27. $i = 0;
  28. while (file_exists($filename)) {
  29. $filename_thumb = 'images/dia' . $i . '_th.jpg';
  30. createThumbnail($filename, $filename_thumb, 0.2);
  31. echo '<a href="' . $filename . '"><img src="' . $filename_thumb . '"></a>';
  32. $i++;
  33. $filename = 'images/dia' . $i . '.jpg';
  34. }
  35. ?>
RAW Paste Data