Created
May 18, 2014 22:24
-
-
Save matthiassturm/913b952b7a5d788cf561 to your computer and use it in GitHub Desktop.
Function to create thumbnails (from 2007)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function thumb_create($p_photo_file, $p_thumb_file, $p_max_size, $p_quality=60) | |
{ | |
$pic = @imagecreatefromjpeg($p_photo_file); | |
if ($pic) | |
{ | |
$thumb = @imagecreatetruecolor($p_max_size, $p_max_size) or die ("Can't create Image!"); | |
$width = imagesx($pic); | |
$height = imagesy($pic); | |
if ($width < $height) | |
{ | |
$twidth = $p_max_size; | |
$theight = $twidth * $height / $width; | |
imagecopyresampled($thumb, $pic, 0, 0, 0, ($height/2)-($width/2), $twidth, $theight, $width, $height); | |
} | |
else | |
{ | |
$theight = $p_max_size; | |
$twidth = $theight * $width / $height; | |
imagecopyresampled($thumb, $pic, 0, 0, ($width/2)-($height/2), 0, $twidth, $theight, $width, $height); | |
} | |
imagejpeg($thumb, $p_thumb_file, $p_quality); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment