Forums / Cotonti / Extensions / [CODE] Square Thumbnails

Lombi
#1 2008-08-05 16:23
Enjoy :)

function sed_createthumb($img_big, $img_small, $small_x, $small_y, $keepratio, $extension, $filen, $fsize, $textcolor, $textsize, $bgcolor, $bordersize, $jpegquality, $dim_priority="Width")
        {
        global $cfg;
        $gd_supported = array('jpg', 'jpeg', 'png', 'gif');
 
        switch($extension) {
                case 'gif': $source = imagecreatefromgif($img_big); break;
                case 'png': $source = imagecreatefrompng($img_big); break;
                default: $source = imagecreatefromjpeg($img_big); break;
                }
 
    $thumb_size = $small_x;
	$width = imagesx($source);
	$height = imagesy($source); 
	
    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);
    imagecopyresampled($new_im,$source,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);
 
        switch($extension)
                {
                case 'gif': imagegif($new_im, $img_small); break;
  				case 'png': imagepng($new_im, $img_small); break;
                default: imagejpeg($new_im, $img_small, $jpegquality); break;
                }
        imagedestroy($new_im);
        imagedestroy($source);
		
        return;
        }
<a href="http://www.domenlo.com">Surreal Art</a>
Trustmaster
#2 2008-08-06 07:43
How do you think it could help with the core?
May the Source be with you!
Kilandor
#3 2008-08-06 08:01
It makes for much nicer thumbnails.
Trustmaster
#4 2008-08-06 08:40
I mean, it depends. Some people want square thumb, some want keep original ratio, etc.
May the Source be with you!
Lombi
#5 2008-08-06 11:21
Right. But the code is here if they want to use squares :)
<a href="http://www.domenlo.com">Surreal Art</a>
simplex
#6 2009-02-05 07:30
Perhaps a "keep aspect ratio" or "square" option should be added into the thumbnail options?
Brock
#7 2009-02-05 07:41
# simplex : Perhaps a "keep aspect ratio" or "square" option should be added into the thumbnail options?

Agreed.
Web Design Database - www.wddb.com
DemptD
#8 2009-05-27 03:52
Umm, where do i add that?
Lombi
#9 2009-05-27 03:57
You replace it with the existing function which is in functions.php
<a href="http://www.domenlo.com">Surreal Art</a>
pieter
#10 2009-05-27 04:08
Is it a resize, or a crop?
... can we help you ...
Lombi
#11 2009-05-27 04:17
Well both. It resizes the shorter axis to your thumb width setting, then crops the longer axis to be the same as the shorter axis. All sites with square thumbs use this algorythm.
<a href="http://www.domenlo.com">Surreal Art</a>