Flickr block square thumbnails
Permalink
May 27, 2009 at 1:07 PM
Through the flickr block, I am trying to come up with a way to resize and crop images gracefully.
I have got a function written, but I am not sure how to incorporate it into the block. That code is:
<?php
function createThumb( $source , $dest ) {
$thumb_size = 100 ;
$size = getimagesize ( $source ) ;
$width = $size [ 0 ] ;
$height = $size [ 1 ] ;
if ( $width > $height ) {
$x = ceil ( ( $width - $height ) / 2 ) ;
$width = $height ;
} elseif ( $height > $width ) {
$y = ceil ( ( $height - $width ) / 2 ) ;
$height = $width ;
}
$new_im = ImageCreatetruecolor( $thumb_size , $thumb_size ) ;
$im = imagecreatefromjpeg( $source ) ;
<?php
function createThumb( $source , $dest ) {
$thumb_size = 100 ;
$size = getimagesize ( $source ) ;
$width = $size [ 0 ] ;
$height = $size [ 1 ] ;
if ( $width > $height ) {
$x = ceil ( ( $width - $height ) / 2 ) ;
$width = $height ;
} elseif ( $height > $width ) {
$y = ceil ( ( $height - $width ) / 2 ) ;
$height = $width ;
}
$new_im = ImageCreatetruecolor( $thumb_size , $thumb_size ) ;
$im = imagecreatefromjpeg( $source ) ;
imagecopyresampled( $new_im , $im , 0 , 0 , $x , $y , $thumb_size , $thumb_size , $width , $height ) ;
imagejpeg( $new_im , $dest , 100 ) ;
}
?>
Does anyone have some suggestions?