Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- $directory = 'img/mems';
- $images = array_filter( scandir($directory), function($name) { return preg_match('/\.jpg/i', $name); } );
- $size = 150;
- foreach ($images as $image) {
- $src = imagecreatefromjpeg("$directory/$image");
- $width = imagesx($src);
- $height = imagesy($src);
- $proportion = $width / $height;
- if ($width > $height) {
- $thumb_width = $size;
- $thumb_height = $size / $proportion;
- }
- else {
- $thumb_width = $size * $proportion;
- $thumb_height = $size;
- }
- $dst = imagecreatetruecolor($thumb_width, $thumb_height);
- imagecopyresampled($dst, $src, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
- imagejpeg($dst, "$directory/thumbs/$image");
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment