Re: [PHP] GD 2.0.28 + PHP 4.4.2 + pixelation :(



Steven Macintyre wrote:
Hi All,

I have done some searching via google and some answers say change
copyimageresampled to copyimageresized etc

which should be the correct; use copyimageresampled()


I have tried all fixes ... to no avail


I have one image here 1280 x 960 (150 dpi) 24 depth

DPI is completely irrelevant.

the '24 depth' sounds like your using a PNG as input rather
that a JPEG (which your function expects)

your not making sure that the new width & height are always
integers. use intval() or ceil() or floor() (depending on your
your and the context)... I have no idea what happens if you pass
floats (or non-numeric data) in the relevant arguments of image*()
functinons but I'm guessing it *could* lead to unexplained weirdness
of some sort.

read the man page for imagejpeg():

http://php.net/manual/en/function.imagejpeg.php

take note of the third argument, personally I always set it to 100,
anything less and clients have a tendency to start complaining about image
quality.



When using the following it pixelates ...

function createthumb($name,$filename,$new_w,$new_h)
{
$system=explode(".",$name);
$src_img=imagecreatefromjpeg($name);
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y)
{
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y)
{
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y)
{
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);

imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

try: imagecopyresampled();

imagejpeg($dst_img,$filename);
imagedestroy($dst_img);
imagedestroy($src_img);
}

Which I am of course calling with
createthumb($add,'../pics/'.$largeval,350,263);

Now ... afaik my new sizes are proportional to the big ones ... but it
pixelates :(

However,

Using an image 1600 x 1200 (96 dpi) 24 depth it works and there is no
pixilation

Can someone perhaps assist now?



Kind Regards,


Steven Macintyre
http://steven.macintyre.name
--

http://www.friends4friends.co.za

.



Relevant Pages