05-17-2008, 05:55 AM
|
#3 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
I did a quick thumbnail function here to show you how simple it really is, it might not be working as im pretty tired and I was about to go to bed ;)
PHP Code:
<?php
/** Assuming $source is an image resource to the image we need to alter */
/** Max width + height */
$width = 100;
$height = 100;
$factor = 1;
if(imagesx($source) > $width)
{
$factor = ($width / imagesx($source));
}
if((imagesy($source) * $factor) > $height)
{
$factor = ($height / imagesy($source));
}
$width = floor(imagesx($source) * $factor);
$height = floor(imagesy($source) * $factor);
$thumbnail = imagecreatetruecolor($width, $height);
$bg = imagecolorallocate($thumbnail, 255, 255, 255);
imagefilledrectangle($thumbnail, 0, 0, (imagesx($thumbnail) - 1), (imagesy($thumbnail) - 1), $bg);
imagecopyresampled($thumbnail, $source, 0, 0, 0, 0, $width, $height, imagesx($source), imagesy($source));
imagedestroy($source);
$source = NULL;
/** $thumbnail is now the generated thumbnail */
?>
__________________
Last edited by Kalle : 05-19-2008 at 12:49 AM.
|
|
|