Skip to content

Instantly share code, notes, and snippets.

@matthiassturm
Created May 18, 2014 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthiassturm/913b952b7a5d788cf561 to your computer and use it in GitHub Desktop.
Save matthiassturm/913b952b7a5d788cf561 to your computer and use it in GitHub Desktop.
Function to create thumbnails (from 2007)
<?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