I'm looking for a way to antialias an image using the GD library.
I have a script that will fetch an image and then resize it and after that add some text to it. But I can't figure out why is the image all jaggy. I tried to use the imagecreate instead of imagecreatetruecolor and the image seems to antialiased but of course the quality is lowered so it actually looked worse.
this

became this
this is the script I'm using
PHP Code:
<?php
$id = $_GET["id"];
$id = preg_replace("/[^a-zA-Z0-9s]/", "", $id);
$id = secure($id);
if(is_numeric($id)){
$query = "SELECT * FROM ".$prefix."owned WHERE aid='$id'";
$result = mysql_query($query);
$num = mysql_numrows($result);
$i=0;
while ($i < 1) {
$aid=@mysql_result($result,$i,"aid");
$name=@mysql_result($result,$i,"name");
$level=@mysql_result($result,$i,"currentlevel");
$i++;
}
if($aid == $id){
$usingimage = "no";
$image = getcurrentimage($id);
$usegd = grabanysetting("gdimages");
$imageinfo = @getimagesize($image);
$imagemime = $imageinfo["mime"];
if(function_exists('imagepng') and $usegd == "yes" and $imagemime == "image/png")
{
$usingimage = "yes";
list($width, $height, $type, $attr) = getimagesize($image);
$newheight = $height + 40;
if($newwidth < 250){
$newwidth = 200;
}
else{
$newwidth = $width;
}
$img_temp = imagecreatetruecolor($newwidth, $newheight);
$alphablending = true;
$img_old = @imagecreatefrompng($image);
imagealphablending($img_old, true);
imagesavealpha($img_old, true);
if($width < 140 AND height < 120){
$wresized = $width;
$hresized = $height;
}
else{
$div = $width / 140;
$wresized = $width / $div;
$hresized = $height / $div;
if($hresized > 120){
$div = $height / 120;
$wresized = $wresized / $div;
$hresized = $hresized / $div;
}
}
ImageCopyResampled(
$img_temp,
$img_old,
0, 0, 0, 0,
$wresized,
$hresized,
$width,
$height
);
$textheight = $hresized;
$image = $img_temp;
$bgi = imagecreatetruecolor($newwidth, $newheight);
$str1 = "".$name;
$str2 = "Level:".$level;
$str3 = "".$domain;
$font = 'fonts/arial.ttf';
$black = imagecolorallocate($image, 10, 10, 10);
imagettftext ($image, 14, 0, 1, $hresized + 2, $black, $font, $str1);
imagettftext ($image, 14, 0, 1, $hresized + 18, $black, $font, $str2);
$background = imagecolorallocate($image, 0, 0, 0);
ImageColorTransparent($image, $background);
header("Content-Type: image/PNG");
ImagePng ($image);
imagedestroy($image);
imagedestroy($img_temp);
imagedestroy($img_old);
imagedestroy($bgi);
}
else{
$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';
$contentType = 'Content-type: '.$extList[ $imageinfo['extension'] ];
if($imageinfo['extension'] =! "image/gif" and $imageinfo['extension'] =! "image/jpeg" and $imageinfo['extension'] =! "image/png"){
die("Hacking Attempt!");
}
else{
$status = "";
header ($contentType);
$status = readfile($image);
if($status == "" or $status == "false" or $status == "FALSE"){
header ("text/plain");
die("Readfile appears to be disabled on your host.");
}
}
}
}
else{
$article_title = $err_idnoexist;
$article_content = $err_idnoexist_text;
}
}
else{
$article_title = $err_idnoexist;
$article_content = $err_idnoexist_text;
}
?>