Skip to content

Instantly share code, notes, and snippets.

@zirosas
Created June 26, 2013 20:12
Show Gist options
  • Save zirosas/5871182 to your computer and use it in GitHub Desktop.
Save zirosas/5871182 to your computer and use it in GitHub Desktop.
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) {
// load image and get image size
$img = imagecreatefromjpeg( "{$pathToImages}" );
$width = imagesx( $img );
$height = imagesy( $img );
// calculate thumbnail size
$new_width = $thumbWidth;
$new_height = floor( $height * ( $thumbWidth / $width ) );
// create a new temporary image
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
// copy and resize old image into new image
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
// save thumbnail into a file
imagejpeg( $tmp_img, "{$pathToThumbs}" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment