Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Overlay text on images without Image::Magick

by reaper9187 (Scribe)
on Jan 13, 2015 at 19:19 UTC ( [id://1113132]=perlquestion: print w/replies, xml ) Need Help??

reaper9187 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
I have a small query regarding overlaying text on images. I know Image::Magick is a popular module to modify the images. But I was wondering if it is possible using any other module ?? I tried using GD but the tests failed similar to what is described here. Any ideas how to overcome this or use any other modules ?? I am even willing to consider doing this without modules but I know it will be very complex.
  • Comment on Overlay text on images without Image::Magick

Replies are listed 'Best First'.
Re: Overlay text on images without Image::Magick
by Anonymous Monk on Jan 13, 2015 at 19:29 UTC
    I know Image::Magick is a popular module to modify the images.

    It is, and in the past I've used it to do what you're asking (code not at hand, sorry). Why not use it? Are there issues with it that we can try to help resolve?

    Did you try installing GD anyway, like the StackOverflow post you linked to suggests, and did it work or not?

    A similar recent thread with some GD sample code: Adding text to an image for printing (not quite the same because there the asker prefers to generate PDFs)

      Found it! From the archives (and tested):

      use Image::Magick; my $image = Image::Magick->new; $image->Read("/tmp/test_in.jpg"); $image->Annotate( text=>"Hello, World!", font=>'sans-serif', fill=>'black', antialias=>'true', pointsize=>16, x=>10, y=>30, ); $image->Write("/tmp/test_out.png");
Re: Overlay text on images without Image::Magick
by reaper9187 (Scribe) on Jan 13, 2015 at 19:35 UTC
    Hi anonymous, Thanks for your quick reply. I am just trying to find a way around this because I am not able to install it on my server .I'd like to save this for a later time. For now, I'm just looking for quick solution around this. I tried installing GD but it throws the following error:
    GD object version 2.46 does not match $GD::VERSION 2.56 at C:/Dwimperl +/perl/lib/ DynaLoader.pm line 213. Compilation failed in require at ab.pl line 1. BEGIN failed--compilation aborted at ab.pl line 1.
    What do you think ?
      I recall fighting something very similar a couple years back. I just installed Citrus Perl along side my standard install and use it any time I need GD.
      GD object version 2.46 does not match $GD::VERSION 2.56 at C:/Dwimperl

      You need to match up your GD c-library version with the Perl module. Either install the latest GD c lib from boutell.com OR try and find an older Perl module that was built against GD 2.46.

      There is also Imager, which is a great Imaging module.

      #!/usr/bin/perl use warnings; use strict; use Imager; my $img = Imager->new(xsize=>400,ysize=>300); $img->box(filled=>1, color=>"ffffff"); #fill the background color my $blue = Imager::Color->new("#0000FF"); my $font = Imager::Font->new( file => 'Generic.ttf', index => 0, color => $blue, size => 30, aa => 1); $img->string( font=>$font, text=>'This is a test string', x=>20, y=>70); $img->write(file=>"$0.jpg", type=>"jpeg") or die "Cannot write file: +", Imager->errstr;
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1113132]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2025-06-21 01:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.