Forum Moderators: coopster

Message Too Old, No Replies

Creating a thumbnail, improving the quality.

         

lajkonik86

3:20 pm on Jan 22, 2005 (gmt 0)

10+ Year Member



Creating a thumb bicubic

// THUMB MAKEN bicubic gedoe
function imageCopyResampleBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
echo 1;
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;

$scaleX2 = $scaleX / 2.0;
$scaleY2 = $scaleY / 2.0;

$tc = imageistruecolor($src_img);

for ($y = $src_y; $y < $src_y + $dst_h; $y++)
{
$sY = $y * $scaleY;
$siY = (int) $sY;
$siY2 = (int) $sY + $scaleY2;

for ($x = $src_x; $x < $src_x + $dst_w; $x++)
{
$sX = $x * $scaleX;
$siX = (int) $sX;
$siX2 = (int) $sX + $scaleX2;

if ($tc)
{
$c1 = imagecolorat($src_img, $siX, $siY2);
$c2 = imagecolorat($src_img, $siX, $siY);
$c3 = imagecolorat($src_img, $siX2, $siY2);
$c4 = imagecolorat($src_img, $siX2, $siY);

$r = (($c1 + $c2 + $c3 + $c4) >> 2) & 0xFF0000;
$g = ((($c1 & 0xFF00) + ($c2 & 0xFF00) + ($c3 & 0xFF00) + ($c4 & 0xFF00)) >> 2) & 0xFF00;
$b = ((($c1 & 0xFF) + ($c2 & 0xFF) + ($c3 & 0xFF) + ($c4 & 0xFF)) >> 2);

imagesetpixel($dst_img, $dst_x + $x - $src_x, $dst_y + $y - $src_y, $r+$g+$b);
}
else
{
$c1 = imagecolorsforindex($src_img, imagecolorat($src_img, $siX, $siY2));
$c2 = imagecolorsforindex($src_img, imagecolorat($src_img, $siX, $siY));
$c3 = imagecolorsforindex($src_img, imagecolorat($src_img, $siX2, $siY2));
$c4 = imagecolorsforindex($src_img, imagecolorat($src_img, $siX2, $siY));

$r = ($c1['red'] + $c2['red'] + $c3['red'] + $c4['red'] ) << 14;
$g = ($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) << 6;
$b = ($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue'] ) >> 2;

imagesetpixel($dst_img, $dst_x + $x - $src_x, $dst_y + $y - $src_y, $r+$g+$b);
}
}
}
}
$originalname = $gamedir . "/images/".$bestandsnaam;
$filename = $gamedir . "/images/thumbs/".$g[$which];
$thumb_w = "85px";
$thumb_h = "62px";
$dst_w = "85px";
$dst_h = "62px";
$dst_x = "0";
$dst_y = "0";
$src_x = "0";
$src_y = "0";
if (preg_match("/jpg¦jpeg/",$extl)){
$src_img=imagecreatefromjpeg($originalname);
}
if (preg_match("/png/",$extl)){
$src_img=imagecreatefrompng($originalname);
}
$src_w=imageSX($src_img);
$src_h=imageSY($src_img);
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);

imageCopyResampleBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
if (preg_match("/png/",$extl)){
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
// eind Thumb Maken

but the quality aint very good still.
What's causing the low quality and how can i improve it?

Also how would i do that effect which you see in the second image with gd?

Hope somebody knows.

[edited by: jatar_k at 6:33 pm (utc) on Jan. 22, 2005]
[edit reason] removed urls [/edit]

Salsa

10:41 pm on Jan 22, 2005 (gmt 0)

10+ Year Member



I haven't messed with GD for a while, but back when I did, I played with all sorts of functions, trying to get it to produce acceptable resampling results. Unless you have no option, my suggestion is to do as I did, and abandon it! See if this thread [webmasterworld.com] helps.

lajkonik86

9:39 pm on Jan 24, 2005 (gmt 0)

10+ Year Member



Well i'll suppose it makes do for now.
A friend of mine is checking some variants on this so i'll sippose it will be ok.

Does anyone of you now how to make a button effect around a picture like paintshoppro does?
With a php script that is offcourse:)

elgumbo

12:16 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



Does anyone of you now how to make a button effect around a picture like paintshoppro does?
With a php script that is offcoursehappy!

You could probably use CSS to do this with the border property.

lajkonik86

12:02 am on Jan 27, 2005 (gmt 0)

10+ Year Member



no it's a fade effect i'm talking about.
I could probably do it if i could put one image on top of the other so to say.
Are there layer possibilities in GD?