Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP GD with anti alias
Old 01-30-2011, 04:17 AM PHP GD with anti alias
Average Talker

Posts: 22
Trades: 0
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_oldtrue);  
      
imagesavealpha($img_oldtrue);
   

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,  
         
0000,  
         
$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($image101010); 

    
imagettftext ($image1401$hresized 2$black$font$str1);
    
imagettftext ($image1401$hresized 18$black$font$str2);


    
$background imagecolorallocate($image000);  
      
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;

}
?>

Last edited by progogi; 01-30-2011 at 04:21 AM..
progogi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-30-2011, 11:36 AM Re: PHP GD with anti alias
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
http://php.net/manual/en/function.imageantialias.php
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is online now
Reply With Quote
View Public Profile
 
Old 01-31-2011, 10:03 AM Re: PHP GD with anti alias
Average Talker

Posts: 22
Trades: 0
Already tried that one before and it has no effect
progogi is offline
Reply With Quote
View Public Profile
 
Old 01-31-2011, 09:04 PM Re: PHP GD with anti alias
RonnieTheDodger's Avatar
Extreme Talker

Posts: 232
Location: Central USA
Trades: 0
Did you look through the posts on that page http://php.net/manual/en/function.imageantialias.php

There is talk of using a hack for fake anti-aliasing on an image by using 'imagecopyresampled'.

There may be other paths to pursue in the other posts. Seems like this has been a nagging problem for a few years.
__________________
Ronnie T. Dodger

[
Please login or register to view this content. Registration is FREE
] [
Please login or register to view this content. Registration is FREE
]
RonnieTheDodger is offline
Reply With Quote
View Public Profile Visit RonnieTheDodger's homepage!
 
Old 01-31-2011, 11:38 PM Re: PHP GD with anti alias
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I've always had best of luck using PNG images with alpha channels. I first create a base image like below and copy other images to the base resource.

PHP Code:
$resource imagecreatetruecolor($totalWidth$totalHeight);
        
imagesavealpha($resourcetrue);
        
imagefill($resource00IMG_COLOR_TRANSPARENT); 
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP GD with anti alias
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22179 seconds with 12 queries