Anti Aliasing
Riggs333 - November 30, 2008 - 00:21
| Project: | Signwriter |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | active |
Description
Not really a bug: I realized problems with missing anti aliasing effect on some fonts.
After looking at the code I added at line 704 in signwriter.module the following:
imageantialias($im, true);it's before
$background = imagecolorallocate($im, $bg[0], $bg[1], $bg[2]);
$foreground = imagecolorallocate($im, $fg[0], $fg[1], $fg[2]);
$shadow_color = imagecolorallocate($im, $shadow_rgb[0], $shadow_rgb[1], $shadow_rgb[2]);This worked for me.
Maybe it should be added in the next version? Or maybe there's a better way to handle it!?

#1
In order to have good looking antialiased heading in 6th Drupal, it's enough to define
your color of the background, even if transparent.
:]
Agileware & Co. - thanks for your work! :]
Szy.
#2
Thanks szy!
@Riggs333 - Can you provide some URL examples where anti-aliases does not work? And details of the signwriter configuration used?
#3
@Agileware - have a white (or any other light one) background on your page,
tickle 'transparent' and leave color value for background empty - then you'll get
ugly black dots around the letters.
Szy.
#4
True.
The answer is indeed to set a proper background color.
BUT it would be better if PNG transparency was being antialiased correctly through the alpha channel. Even with PNG I was seeing black chunks.
imagesavealpha() may help if imageantialias() doesn't.
Another suggested approach I saw in php.net was to clear the background by filling the image with solid transparent bg color before starting to draw on it.
#5
Subscribing. This module seems perfect for a project of mine, but only if the images are PNGs with alpha channel transparency.
#6
I borrowed this little piece of code from textimage and it works for 6.x-1.1.
Add this just before line 927 :
$blankpng = "iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29m"
."dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADqSURBVHjaYvz//z/DYAYAAcTEMMgBQAANegcCBNCg"
."dyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAAN"
."egcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQ"
."oHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAA"
."DXoHAgTQoHcgQAANegcCBNCgdyBAgAEAMpcDTTQWJVEAAAAASUVORK5CYII=";
$im = imagecreatetruecolor($width, $height);
$b = imagecreatefromstring(base64_decode($blankpng));
imagealphablending($im, FALSE);
imagesavealpha($im, TRUE);
imagecopyresized($im, $b, 0, 0, 0, 0, $width, $height, imagesx($b), imagesy($b));
This should also work with 5.x.
Should I open a separate issue for 6.x branch ?
#7
No, it's the same issue for both so this one will do for both versions.
#8
Hi guys,
If you're stealing code from my dear Textimage (I jest, steal away :)) you should probably take code from the latest versions.
The transparency support has been vastly improved since the code in #6.
Try the following when creating a transparent background:
$image = imagecreatetruecolor(width, $height);$back = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefill($image, 0, 0, $back);
Cheers,
Deciphered (maintainer of Textimage).
#9
Indeed. an encoded PNG looks like a terrible idea. Yes, just filling in with transparent is what you need!
#10
Deciphered & dman,
I am not even a good thief ;) Code from latest version seems more efficient, I'll give it a try, thanks !
#11
I have tried to use the #8 code snippet from Deciphered, but i have unconsistent results. Preview seems fine but generated images appear with a black background and fuzzy edges. For now i will stick with the transparent pixel trick, but i'll try harder later.
#12
btw, to work with Signwriter, code snippet should be :
$im = imagecreatetruecolor($width, $height);$back = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $back);
#13
jide's version works nicely. Thanks a lot ;). That was exactly what I was looking for.
#14
Hello,
i'Ve got a question, i tried using the version 5.x-1.5 and 5.x-1.x-dev, but in both i have no anti-aliasing. I tried using the background-transparent-but-color-trick but it won't work.
Can somebody tell me, where the lines
$im = imagecreatetruecolor($width, $height);$back = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $back);
should be placed in 5.x-1.5 to get i working?
Thanks in advanced for your help and thanks for this awesome and useful tool.
regards
Stefan
#15
#16
To use my little hack on the 6.x-2.0-beta1 version, add the following snippet on line 732 :
<?php
$blankpng = "iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29m"
."dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADqSURBVHjaYvz//z/DYAYAAcTEMMgBQAANegcCBNCg"
."dyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAAN"
."egcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQ"
."oHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAA"
."DXoHAgTQoHcgQAANegcCBNCgdyBAgAEAMpcDTTQWJVEAAAAASUVORK5CYII=";
$image->im = imagecreatetruecolor($width, $height);
$b = imagecreatefromstring(base64_decode($blankpng));
imagealphablending($image->im, FALSE);
imagesavealpha($image->im, TRUE);
imagecopyresized($image->im, $b, 0, 0, 0, 0, $width, $height, imagesx($b), imagesy($b));
?>
#17
http://us.php.net/manual/en/function.imageantialias.php says:
Maybe the same is true for antialiased text.
Last time when I wanted to anti-alias some GD imagery (rounded corners), I simply created the image in a higher res w/o antialiasing, and then scaled it down with a home-made alpha-aware per-pixel sampling.
It is important to do the weights correctly when scaling down.
(I could post some code, but I would have to spice it up a bit with comments - and I'm too lazy for that)
EDIT:
The hack #16 works for me.
#18
I'm not trying to drive traffic to TextImage, if anything I'm still interested in talking about a merge, but I spent a huge amount of time tweaking the anti-aliasing, transparency and rotation functionality and the code I used and provided a snippet at #8 is much more efficient than that of #16. I would urge the developers to look at the TextImage code (http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/textimage/?...) and borrow code where needed.
Cheers,
Deciphered.
#19
Or alternatively, paint a transparent rectangle (imagefilledrectangle).
Of course, in combination with imagealphablending and imagesavealpha.
#20
Using: signwriter 6.x-2.0-beta1
Am I missing something? I can't seem to get the jaggies to go away, even with the above hacks.
$imto$image->im) → unsuccessful. Giving up because maybe I misunderstood what this module can do. :(Is anyone able to get this to work with levels of alpha transparency? I'm able to get the jaggies to match the background color, but I am using random images and Flash movies behind the rendered type. I need PNG-24 levels of transparency or have to go back to sIFR.
#21
If i remember well, you should NOT check the transparency checkbox when using the hack to make it work.