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!?

CommentFileSizeAuthor
#20 Picture 1.png88.9 KBdcasey
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

szy’s picture

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.

Agileware’s picture

Status: Active » Postponed (maintainer needs more info)

Thanks szy!

@Riggs333 - Can you provide some URL examples where anti-aliases does not work? And details of the signwriter configuration used?

szy’s picture

@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.

dman’s picture

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.

smithn.nc’s picture

Subscribing. This module seems perfect for a project of mine, but only if the images are PNGs with alpha channel transparency.

jide’s picture

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 ?

Agileware’s picture

Version: 5.x-1.5 » 6.x-1.x-dev
Status: Postponed (maintainer needs more info) » Active

No, it's the same issue for both so this one will do for both versions.

Deciphered’s picture

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).

dman’s picture

Indeed. an encoded PNG looks like a terrible idea. Yes, just filling in with transparent is what you need!

jide’s picture

Deciphered & dman,

I am not even a good thief ;) Code from latest version seems more efficient, I'll give it a try, thanks !

jide’s picture

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.

jide’s picture

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);
Cool_Goose’s picture

jide's version works nicely. Thanks a lot ;). That was exactly what I was looking for.

h-man24’s picture

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

Agileware’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
jide’s picture

To use my little hack on the 6.x-2.0-beta1 version, add the following snippet on line 732 :

  $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));
donquixote’s picture

http://us.php.net/manual/en/function.imageantialias.php says:

Using antialiased primitives with transparent background color can end with some unexpected results. The blend method uses the background color as any other colors. The lack of alpha component support does not allow an alpha based antialiasing method.

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.

Deciphered’s picture

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.

donquixote’s picture

Or alternatively, paint a transparent rectangle (imagefilledrectangle).
Of course, in combination with imagealphablending and imagesavealpha.

dcasey’s picture

FileSize
88.9 KB

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.

  • First try: I've checked the transparent box. → no joy
  • Second try: Transparent box checked, picked a color #00ff00 → nifty green jaggies around
  • Third try: Same as above, uploaded & added a background image with #00ff00 solid fill → same result as previous, sadness
  • Forth try: Added hack #12 on line 732 → same…
  • Fifth – seventh: first three trys with new hack → same, frustration setting in…
  • …tried hacking the hack (changing $im to $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.

jide’s picture

If i remember well, you should NOT check the transparency checkbox when using the hack to make it work.

juanqui_cieri’s picture

That's right, after unchecking "transparent" checkbox in Background Section the code provided in #16 works fine.

JonesUI’s picture

Deciphered's code snippet from #8 worked for me...

I'm using 6.x-2.x-dev

Added the snippet just after line 747 ( // pre allocate the colors )

Is Agileware still maintaining this code?
Its been quite a while since I've seen any responses from him/her.

JonesUI’s picture

Followup to #23:

Deciphered's snippet (#8) seemed to work only with SW images that had already been cached.
When attempting to create new SW images, it would only generate black rectangles where the text should be.

I switched to using the snippet from #16 with version 6.x-2.0-beta1 and the jagged pixels are gone and transparency is working correctly.

Agileware’s picture

Still maintaining signwriter but just very busy with paid work at the moment.

If anyone can make patches it speeds up the process a lot and is greatly appreciated.

Also, if anyone wants to help co-maintain this module send me a message via my contact form.

aschiwi’s picture

Great, thanks for the code in #16. In Signwriter 6.x-2.0-beta2, put the code in line 748.