Git Product home page Git Product logo

perl-gd's Introduction

GD.pm -- A perl5 interface to Thomas Boutell's gd library.

ABSTRACT:

This is a autoloadable interface module for libgd, a popular library
for creating and manipulating PNG files.  With this library you can
create PNG images on the fly or modify existing files.  Features
include:

a.  lines, polygons, rectangles and arcs, both filled and unfilled
b.  flood fills
c.  the use of arbitrary images as brushes and as tiled fill patterns
d.  line styling (dashed lines and the like)
e.  horizontal and vertical text rendering
f.  support for transparency and interlacing
g.  support for TrueType font rendering, via libfreetype.
h.  support for spline curves, via GD::Polyline
i.  support for symbolic font names, such as "helvetica:italic"
j.  support for symbolic color names, such as "green", via GD::Simple
k.  produces output in png, gif, jpeg, xbm and other formats supported by libgd
l.  produces output in svg format via GD::SVG.

For full information on usage, see the accompanying man and html
documentation. Also check the FAQ at the bottom of this document.

INSTALLATION:

1. Windows users can find a binary PPM package in the repositories at
these sites:

        http://trouchelle.com/perl/ppmrepview.pl
        http://www.bribes.org/perl/ppmdir.html

These packages are not always updated to the most recent version, but
GD is pretty stable and you usually won't miss the bleeding edge
version.

For Unix/darwin users and those who have a developer's kit installed
on Windows (e.g. cygwin):

2.  Make sure you have downloaded and installed the following packages:

	a. Perl 5.6.0 or higher:
		http://www.perl.com/

	b. The gd graphics library:
		http://libgd.org

	c. The PNG graphics library:
		http://www.libpng.org/pub/png/libpng.html

	d. The zlib compression library:
		http://www.gzip.org/zlib/

	(OPTIONAL)

	e. The FreeType font rendering library for TrueType fonts:
		http://www.freetype.org/

        f. The JPEG library, version 6b or later:
                ftp://ftp.uu.net/graphics/jpeg/

        g. The XPM library, a standard part of modern X Windows 
	   distributions.  If you don't have a modern
           version of X, don't try to get XPM working.

3. On darwin, you can use these package managers to resolve dependencies and
build libgd:

        i.  MacPorts http://www.macports.org/
	ii. Homebrew http://mxcl.github.io/homebrew/

If this module fails to compile and link, you are probably using an
older version of libgd.  Symptoms of this problem include errors about
functions not being recognized in the gd.h header file, and undefined
symbols from the linker.  If you are having this type of error, please
REMOVE all versions of libgd, gd.h from your system and reinstall
libgd 2.0.28 or higher.  Do not contact Lincoln for help until you
have done this.

Use GD 1.41 for libgd versions 1.8.4 and lower.

3.  Unpack the tar file:

	zcat GD-2.XX.tar.gz | tar xvf -

    (Where "XX" is the most recent revision number.)  This will create
    the directory GD-2.XX.

4.  To compile GD.pm:

	a.  cd GD-2.XX
	b.  perl Makefile.PL
	c.  make
        d.  make test
	f.  sudo make install

    This will create GD.pm and install it into
    the system-wide Perl library directory.  You'll need root
    privileges to do the install step.  If you don't have them, see below.

    During step (b), Makefile.PL will look for the program gdlib-config or gdlib.pc
    that newer versions of libgd install for you.  If this program is not present, the
    Makefile.PL script will ask you whether to build support for
    JPEG, FreeType and/or XPM image formats.  Please answer "y" (the default) 
    if libgd was built with the feature, and "n" if it was not.  Failure
    to answer correctly will lead to link errors.

    If, during step (b) you see notes about missing libraries, then this
    module will probably not link correctly, even though the warning may say
    "probably harmless".    

5.  Before you install GD, you will want to run the regression tests.  You
    can do this after the "make" step by typing:

	make test

6.  There are some demos you can run in ext/GD/demos.  They print PNG
    files to standard output.  To view the files, pipe their
    output to "display" or "xv" in this way:

	a.  cd GD-2.XX/demos
	b   perl shapes.pl | display -

    You will need a graphics program that can read and display PNG
    format.  I recommend Image::Magick's display program, available from
    ftp://ftp.wizards.dupont.com/pub/ImageMagick/
    If you don't have any display programs handy, you can save to a
    temporary file and display with recent versions of Netscape or
    Internet Explorer.

7.  A program named fonttest is included in this package under demos.  This 
    generates an image showing all the built-in fonts available.  If you have
    built libgd with TrueType support, and you have a directory containing
    some TrueType fonts, you can create a simple font listing by running
    the program truetype_test, also located in demos.

8.  See demos/gd_example.cgi for an example of how to use GD to create
    a picture dynamically with a CGI script.  It's intended to be run
    under a Web server.  To see it work, install it in your server's
    cgi-bin/ directory and invoke it from a browser by fetching a URL like:

	http://your.site/cgi-bin/gd_example.cgi

IF YOU RUN INTO PROBLEMS

If the make and install all seem to go well but you get errors like
"Fatal error: can't load module GD.so", or "Fatal error: unknown
symbol gdFontSmall" when you try to run a script that uses GD, you may
have problems with dynamic linking.  Check whether other
dynamically-linked Perl modules such as POSIX and DB_File run
correctly.  If not, then you'll have to link Perl statically, as
described above.  Other problems may be fixed by compiling libgd as a
shared library, as described in step (2) of the installation
instructions.

If you are trying to compile and link GD on a Windows or Macintosh
machine and fail, please verify that you are able to build the Perl
distribution from source code.  If you can't do that, then you don't
have the compiler/linker/make tools required for building Perl
modules.  You may not even need to do this, as ActiveState and MacPerl
both include precompiled versions of GD.

If you have problems and can't solve it on your own, post a message to
the newsgroup "comp.lang.perl.modules".  There are some systems that
require obscure compiler and linker options in order to compile
correctly, and unfortunately I have a limited number of systems at my
disposal.  You're much more likely to get correct answers from the
gurus on the newsgroup than from myself.

THE GD::SIMPLE LIBRARY

GD::Simple is a simplified API for GD. It supports turtle graphics, a
unified interface for drawing text, and symbolic color names (like
"green").  Run "perldoc GD::Simple" for information on using it.

The GD::SVG LIBRARY

GD::SVG, which is available separately on CPAN, provides a subset of
GD method calls. For this subset, you can create images in SVG
(scalable vector graphics) format.

THE QUICKDRAW LIBRARY

This is no longer supported.

FREQUENTLY ASKED QUESTIONS

1. I get a warning about prerequisite Math::Trig not being found

   The version of Math::Trig that comes with Perl version 5.6.0 and
   lower has a bug in it that causes it not to be found even when it
   is installed.  Try running perl -MMath::Trig -e0 from the command
   line.  If you get no errors, go ahead and install GD. If you get an
   error, install Math::Trig from CPAN.

2. Why do I get errors about functions not being found when building this module?

   You need libgd (the C library that does all the work) version 2.0.28 or
   higher.  Older versions will give you errors during GD
   installation. Get the latest version from http://libgd.org and install it.
   Sometimes just installing the new version of libgd is not enough: you must
   remove the old library first. Find the gd.h include file and all libgd files
   and remove them from your system.

3. Why do I get errors about symbols being undefined when building this module?

   See (1).

4. The %&#&#! thing doesn't compile at all! I'm getting lots of compile errors!

   Does "make" fail with messages like these?

   GD.xs: In function 'newDynamicCtx':
   GD.xs:440: error: 'gdIOCtx' has no member named 'gd_free'
   GD.xs: In function 'gd_cloneDim':
   GD.xs:460: error: 'struct gdImageStruct' has no member named 'alpha'
   GD.xs:460: error: 'struct gdImageStruct' has no member named 'alpha'
   GD.xs:466: error: 'struct gdImageStruct' has no member named 'thick'
   GD.xs:466: error: 'struct gdImageStruct' has no member named 'thick'

   If so, then you may have an old gd.h include file located somewhere
   in your system include path. Please find it and remove it. A typical
   location is /usr/include/gd.h. The way to make sure you are removing
   the correct gd.h is to run "gdlib-config --cflags" to find out where
   the current gd.h lives:

      % gdlib-config --cflags
      -I/usr/local/include

   This tells you that /usr/local/include/gd.h is the correct gd.h. Please
   find and remove any other gd.h.

5. My scripts fail with "Can't locate object method 'png' via package "GD::Image".

   libgd can now be built with support for one or more of the PNG, GIF, XPM or 
   JPEG formats. If one or more of these formats are not supported by libgd, then
   the corresponding GD::Image methods will be unavailable.  Unfortunately, many
   older scripts assume that the png() method will always be present.  You can
   work around this issue with code like the following:

      my $image = $gd->can('png') ? $gd->png : $gd->gif;

   or if you prefer eval {}

      my $image = eval {$gd->png} || $gd->gif;

   As of libgd 2.0.33, GIF support is always compiled in, so (for the time being!)
   this is a safe fallback.
   
6. Is there a utility to convert X Windows BDF fonts into GD fonts.

   Yes.  See the utility bdf2gdfont.pl.  Run "bdf2gdfont.pl -h" to get help
   on using this.

7. Does GD run with Macintosh OS X?

   Yes.  GD compiles just fine under OSX.  However, you may need to
   remove old versions of libgd, libpng, and libz and reinstall the
   current versions before you try to install GD.

8. Does GD run with Win32 Perl?

   The latest ActiveState binaries for Win32 systems come with GD
   already compiled in and ready to go. I don't own any Win32 systems,
   and cannot provide you with help in compiling GD from scratch on such 
   systems. Github actions and appveyor are used to test the windows builds.

9. GD won't compile on system XX.

   Because libgd relies on multiple external libraries, GD does as well.  
   Unfortunately, different systems place their libraries in different
   places and sometimes are picky about the order in which libraries 
   are linked.  The best thing to do is to install the latest version of
   libgd. Recent versions of libgd contain a gdlib-config utility, which
   GD will use to determine which libraries are necessary and in which
   order to link them.

   Another thing to be aware of is that some Unix distributions provide
   a faulty precompiled version of Perl which is unable to build and
   load new C-based modules (like this one).  If you are getting errors
   like this:

   /arch/auto/GD/GD.so: undefined symbol: SetCPerlObj at ....

   then you may have such a faulty version of Perl.  The most reliable
   thing to do is to recompile Perl from source code, thereby ensuring
   that it is complete.

10. When I try to load an XPM file, all I get is blackness!

   The libgd createFromXpm() function works with some XPM files, and
   not with others.  The problem is buried deep in the libXpm library
   somewhere.

11. The stringFTCircle() method doesn't work!

   I know.  I think this might be a problem in libgd because I have
   never gotten it to work as a C program.  If you have any insight
   into this problem let me know.

12. Test XX fails

   The regression tests for GD involve generating images, saving
   them as PNG, JPEG or GIF files, and then comparing the files bit-for-bit
   to known "correct" files.  Sometimes one of the underlying
   C libraries such as libz, libpng or libgd is updated, causing 
   GD to generate an image that is subtly different.  These differences
   are usually insignificant, such as a reordering of colors in the
   color table, but they will call isolated tests to fail.  If you
   are seeing the great majority of GD tests pass, but one or two
   fail, then you are probably seeing the effect of a new library.
   Just go ahead and install GD and drop me a note about the problem.

BUG REPORTS

Please report bugs, feature requests and propose code changes using
the GitHub repository at https://github.com/lstein/Perl-GD. We do not
check the CPAN RT bug system with any frequency.

ACKNOWLEDGEMENTS:

I'd like to thank Jan Pazdziora, Geoff Baysinger, and David Kilzer for
their contributions to the library, as well as Thomas Boutell who
wrote libgd.

SOURCE CODE AND UPDATES:

The current version of GD can be found in CPAN. The development
version can be found on GitHub at https://github.com/lstein/Perl-GD.

AUTHOR and LICENSE

Copyright 1995-2014 Lincoln Stein <[email protected]>
Maintainance taken over by Reini Urban 2017.

This package and its accompanying libraries is free software; you can
redistribute it and/or modify it under the terms of the GPL (either
version 1, or at your option, any later version) or the Artistic
License 2.0.  Refer to LICENSE for the full license text.
package for details.

perl-gd's People

Contributors

burak avatar corion avatar ffontaine avatar fperrad avatar guimard avatar hakonhagland avatar jforget avatar lorenzota avatar lstein avatar melak avatar mishin avatar pghmcfc avatar philterpaper avatar pryrt avatar romainnaour avatar rurban avatar sauoq avatar shawnlaffan avatar toddr avatar twata1 avatar yuriyyev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

perl-gd's Issues

Build.PL missing custom install prefix

I need to install the GD module in a separate directory other than the default Perl modules one. The problem is that Build.PL does not seem to support a custom install prefix from command line and installing with the Makefile.PL does not seem to work since no object files are generated.

CPAN download, redirect loop

The default download location is broken. Best interim solution is to download from http://cpan.metacpan.org/authors/id/L/LD/LDS/GD-2.53.tar.gz.

For those using cpanm:

cpanm --mirror http://cpan.metacpan.org

Forking vs read_color_table()

Consider the following:

use GD::Simple;

for (1..100)
{
    my $pid = fork;

    if(!defined($pid))
    {
        next;
    }

    if($pid == 0)
    {
        GD::Simple->new->bgcolor('transparent');
        exit;
    }
}

This fails more often than not, producing the following output:

unknown color at /usr/local/lib/perl5/site_perl/mach/5.26/GD/Simple.pm line 856, <DATA> line 52.
unknown color at /usr/local/lib/perl5/site_perl/mach/5.26/GD/Simple.pm line 856.
unknown color at /usr/local/lib/perl5/site_perl/mach/5.26/GD/Simple.pm line 856, <DATA> line 55.
unknown color at /usr/local/lib/perl5/site_perl/mach/5.26/GD/Simple.pm line 856.
[...]

With some debugging put in, it becomes reasonably clear that DATA's position is literally all over the place, reading completely random stuff from completely random places in Simple.pm. The gist of this obviously comes down to DATA being a typeglob and all that, in a concurrent scenario like the above, several processes read from it, some will be missing some data, eventually one of them will also make it skip past __END__, and after a short while everything goes bonkers.

I've been playing with a couple of naive ideas for a fix, but the only real solution seems to be not building %COLORS at run-time.

Any other suggestions or observations perhaps before I put in a pull request with a static table?

test cases fail for Windows. libgd missing GIF support

Hi,

I am trying to execute test cased for GD-2.68. with Libgd and GD module build with VS2013
But the test case fails with below error

Can't locate object method "newFromGif" via package "GD::Image" at t\transp.t line

"-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t\*.t
t\fork.t .................. skipped: Test::Fork required
t\GD.t .................... 1/13 # Testing gd 2.2.5 using gd2 support.
# ignore corrupt png error messages...
t\GD.t .................... ok
t\HSV.t ................... ok
t\Polyline.t .............. ok
t\transp.t ................ Can't locate object method "newFromGif" via package "GD::Image" at t\transp.t line 13.
t\transp.t ................ 1/12 # Looks like your test exited with 255 just after 1.
t\transp.t ................ Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 11/12 subtests
t\z_kwalitee.t ............ skipped: No RELEASE_TESTING
t\z_manifest.t ............ skipped: requires a git checkout and a unix for git and diff
t\z_pod-spell-mistakes.t .. skipped: No RELEASE_TESTING
t\z_pod.t ................. skipped: No RELEASE_TESTING

Test Summary Report
-------------------
t\transp.t              (Wstat: 65280 Tests: 1 Failed: 0)
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 12 tests but ran 1.
Files=9, Tests=16,  2 wallclock secs ( 0.06 usr +  0.03 sys =  0.09 CPU)
Result: FAIL
Failed 1/9 test programs. 0/16 subtests failed.
NMAKE : fatal error U1077: 'C:\this_is_a_fake_path\this_is_a_fake_path\this_is_a_fake_path\this_is_a_fake_path\this_is_a_fake_path\this_is_a_fake_path\this_is_a_fake_path\bin\iwperl.exe' : return code '0xff'
Stop.

Please let me know any inputs

Thanks,
Jamey

add_frame_data

Described in the line #546 of GD.pm (typical usage sequence) following instruction:

add_frame_data($frame);

causes an error:

Undefined subroutine &main::add_frame_data called at <programname> line <linenumber>

newFromPng() leads to "Uninitialized value $pkg at Symbol.pm line 53"

After switching from Ubuntu 20 LTS (Perl Lib GD Version 2.71) to Ubuntu 22 LTS (Perl Lib GD Version 2.712.76) every Perl -w call of GD::Image->newFromPng() leads to the following error output:

Use of uninitialized value $pkg in concatenation (.) or string at /usr/lib/x86_64-linux-gnu/perl-base/Symbol.pm line 53.

In a web server environment this is annoying, because it creates an entry in the Apache server error log every time.

get error report when using heatmap.pl

(perl /NAS4/lien/Hi-C/scripts_dekkerlab/cworld-dekker-master/scripts/perl/heatmap.pl -i K5__30000__10.matrix.gz -i GM__30000__10.matrix.gz -o K5__GM__30000__10__median)
I just want to test the script (heatmap.pl),but got error report.
The error report:
Can't load '/NAS7/home/caulien/bin/localperl/lib/site_perl/5.26.0//x86_64-linux/auto/GD/GD.so' for module GD: libiconv.so.2: cannot open shared object file: No such file or directory at /NAS7/home/caulien/bin/localperl/lib//5.26.0/x86_64-linux/DynaLoader.pm line 193.
at /NAS7/home/caulien/bin/localperl/lib/site_perl/5.26.0//x86_64-linux/GD/Simple.pm line 160.
Compilation failed in require at /NAS7/home/caulien/bin/localperl/lib/site_perl/5.26.0//x86_64-linux/GD/Simple.pm line 160.
BEGIN failed--compilation aborted at /NAS7/home/caulien/bin/localperl/lib/site_perl/5.26.0//x86_64-linux/GD/Simple.pm line 160.
Compilation failed in require at /NAS4/lien/Hi-C/scripts_dekkerlab/cworld-dekker-master/scripts/perl/heatmap.pl line 13.
BEGIN failed--compilation aborted at /NAS4/lien/Hi-C/scripts_dekkerlab/cworld-dekker-master/scripts/perl/heatmap.pl line 13.

how can I deal with it? Thank you so much!

Issues with package versions

Hi,

Despite having updated to latest version of GD I still get listed in the CPAN tool:

GD::Polygon undef 0.2 RURBAN/GD-2.69.tar.gz

The problem appears to be that the GD::Polygon package itself has no version, but the GD::Polyline package has a version of "0.2" and then overrides the GD::Polygon package

package GD::Polyline;

############################################################################
#
# GD::Polyline
#
############################################################################
#
# What's this?  A class with nothing but a $VERSION and @ISA?
# Below, this module overrides and adds several modules to 
# the parent class, GD::Polygon.  Those updated/new methods 
# act on polygons and polylines, and sometimes those behaviours
# vary slightly based on whether the object is a polygon or polyline.
#

use vars qw($VERSION @ISA);
$VERSION = "0.2";
@ISA = qw(GD::Polygon);


package GD::Polygon;

############################################################################
#
# new methods on GD::Polygon
#
############################################################################

I think the fix is to either remove the version or to align it with the main package version?

Thanks in advance

2.81: test suite fails

+ cd GD-2.81
+ /usr/bin/make -O -j48 V=1 VERBOSE=1 test TEST_VERBOSE=1
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- GD.bs blib/arch/auto/GD/GD.bs 644
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(1, 'blib/lib', 'blib/arch')" t/*.t
t/autodetect.t ............
1..12
ok 1 - use GD;
ok 2 - gif detected
ok 3 # skip No PNG support
ok 4 # skip No JPEG support
ok 5 # skip No TIFF support
ok 6 # skip No AVIF support
ok 7 # skip No HEIF support
ok 8 # skip No WEBP support
ok 9 - wbmp detected
ok 10 - bmp detected
ok 11 # skip No XPM support
ok 12 - xbm detected
ok
t/caller.t ................
ok 1 # skip No PNG support
ok 2 - no warnings
1..2
ok
t/fork.t .................. skipped: Test::Fork required
# Testing gd 2.3.3 using png support.

#   Failed test 'unable to generate comparison image for test 1 with png: Can't locate object method "newFromPng" via package "GD::Image" at (eval 17) line 1.
# '
#   at t/GD.t line 271.
Can't locate object method "newFromPng" via package "GD::Image" at t/GD.t line 82.
# Looks like your test exited with 255 just after 3.
t/GD.t ....................
1..15
ok 1 - use GD;
ok 2 - use GD::Simple;
not ok 3 - unable to generate comparison image for test 1 with png: Can't locate object method "newFromPng" via package "GD::Image" at (eval 17) line 1.
#
Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 13/15 subtests
t/HSV.t ...................
1..1
ok 1
ok
t/Polyline.t ..............
1..1
# Running under perl version 5.038002 for linux
# Current time local: Sat May  4 22:25:26 2024
# Current time GMT:   Sat May  4 22:25:26 2024
# Using Test.pm version 1.31
ok 1
ok
t/transp.t ................
1..12
ok 1 - use GD;
ok 2 - image is not transparent
ok 3 - transparency preserves RGB before 0
ok 4 - transparency preserves RGB after
ok 5 # skip No JPEG support
ok 6 # skip No JPEG support
ok 7 # skip No JPEG support
ok 8 # skip No JPEG support
ok 9 # skip No JPEG support
ok 10 # skip No JPEG support
ok 11 # skip No JPEG support
ok 12 # skip No JPEG support
ok
t/windows_bmp.t ...........
1..4
ok 1 - use GD;
ok 2 - windows bmp does not return undef
ok 3 - windows bmp has width 2
ok 4 - windows bmp has height 2
ok
t/z_kwalitee.t ............ skipped: No RELEASE_TESTING
t/z_manifest.t ............ skipped: requires a git checkout and a unix for git and diff
t/z_pod-spell-mistakes.t .. skipped: No RELEASE_TESTING
t/z_pod.t ................. skipped: No RELEASE_TESTING

Test Summary Report
-------------------
t/GD.t                  (Wstat: 65280 Tests: 3 Failed: 1)
  Failed test:  3
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 15 tests but ran 3.
Files=12, Tests=35,  1 wallclock secs ( 0.07 usr  0.04 sys +  0.76 cusr  0.18 csys =  1.05 CPU)
Result: FAIL
Failed 1/12 test programs. 1/35 subtests failed.
make: *** [Makefile:1034: test_dynamic] Error 255

Detecting JPEG images using magic numbers

Hi,

I am creating a new image using GD::Image->new($jpg_file), where $jpg_file is a filename pointing to a file on disk.
The JPEG file on disk is valid. But the function returns undef, as the first four bytes of the JPEG image on disk does not match the pattern in the _image_type function: The fourth byte is \376.
If I create the GD image using newFromJpeg, it works fine.
Do you know if there are any issues related to this?
I see that the magic function detection was changed in v2.42. Unfortunately, I am not aware of the various patterns which can occur as the first four bytes in JPEG files.
By the way, we are using GD::Image for sizing images in various formats.

Kind regards,
Geir Myklebust

Is GD::Image::copyRotated compatible with libGD 3.0?

Running Fedora Linux GD::Image::copyRotated() appears to incorrectly throw a version error:

Environment:
matt@aslan:276% cat /etc/fedora-release
Fedora release 20 (Heisenbug)
matt@aslan:277% rpm -q gd
gd-2.1.0-8.fc20.x86_64
matt@aslan:278% perl_module_version GD GD::Image
GD : 2.49
GD::Image : 2.38
matt@aslan:279% rpm -ql gd | grep libgd
/usr/lib64/libgd.so.3
/usr/lib64/libgd.so.3.0.0

Symptom:
matt@aslan:280% perl rotate_image test.jpg 270
libgd 2.0.33 or higher required for copyRotated support at /home/matt/src/LLS/Graphics.pm line 368.
matt@aslan:281% grep copyRotated LLS/Graphcis.pm
my ($w, $h) = $image->getBounds(); $image->copyRotated($oldimage, $h/2, $w/2, 0, 0, $w, $h, 270);

What additional detail can I provide?

autodetect.t fails (TIFF related) on newer systems (ubuntu 24.04, debian trixie...)

On an ubuntu 24.04 with system libgd-dev installed:

TIFFFetchDirectory: Warning, Requested memory size for TIFF directory of 192 is greather than filesize 0. Memory not allocated, TIFF directory not read.
TIFFReadDirectory: Failed to read directory at offset 140.
GD Warning: Cannot open TIFF imagegdImageCreateFromTiff error at /home/cpansand/.cpan/build/2024060919/GD-2.82-1/blib/lib/GD/Image.pm line 281.
# Looks like your test exited with 255 just after 4.
t/autodetect.t ............
Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 8/12 subtests
...

please add support for BMP to GD::Image

libgd has included Windows Bitmap .bmp support (gdImageBmp and gdImageCreateFromBmp and associated) since libgd 2.1.0-alpha1.

This is different from WBMP support (WBMP is a monochrome format, whereas Windows BMP allows anything from monochrom to full-color images; WMBP format uses gdImageWBMP/gdImageCreateFromWBMP/etc, which you have already implemented with newFromWBMP and ->wbmp).

I have confirmed with GD 2.76 libgd 2.2.5 (strawberry perl v5.32.1) that if I output a GD::Image with $img->wbmp($fg), then no default Microsoft tool (mspaint.exe, Photo Viewer, etc) can read it as a Windows Bitmap (.bmp), because it's not a valid Windows bitmap file. But if I get a tool (like ImageMagick) that understands the monochrome WBMP format, it reads it just fine. Similarly, ->newFromWBMP cannot read a standard Windows .bmp file.

There is no GD::Image::newFromBmp() or ->bmp() pair for input/output of the Windows Bitmap format (Undefined subroutine &GD::Image::newFromBmp).

Since gdImageBmp and gdImageCreateFromBmp already exist in libgd 2.1 and newer (and are thus present in my libgd 2.2.5 or in the libgd 2.3.3 that you've supported since at least v2.74), it would be really nice if support for that feature of libgd could be added to GD::Image. (If you don't want to try to auto-identify it for GD::Image::new(), that's fine with me.)

But whether or not it gets added, the documentation for GD::Image->newFromWBMP should be changed for two things:

  1. Since WBMP is not a Windows BMP, and is not compatible with the windows bitmap format, it shouldn't say it is.
  2. Since WBMP is a monochrome format, a truecolor option isn't needed.

Thank you.

provides dropped out of META.yaml in 2.59

diff --git a/META.yml b/META.yml
index f8f02021a..c9e045951 100644
--- a/META.yml
+++ b/META.yml
@@ -1,38 +1,26 @@
 ---
-abstract: 'Perl interface to the gd2 graphics library'
+abstract: 'Interface to Gd Graphics Library'
 author:
-  - 'Lincoln Stein <[email protected]>'
+  - 'Lincoln Stein ([email protected])'
 build_requires:
-  ExtUtils::CBuilder: '0'
+  ExtUtils::MakeMaker: '0'
 configure_requires:
-  Module::Build: '0.42'
+  ExtUtils::MakeMaker: '0'
 dynamic_config: 1
-generated_by: 'Module::Build version 0.421, CPAN::Meta::Converter version 2.142690'
-license: perl
+generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010'
+license: unknown
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
   version: '1.4'
 name: GD
-provides:
-  GD:
-    file: lib/GD.pm
-    version: '2.56'
-  GD::Group:
-    file: lib/GD/Group.pm
-    version: '1'
-  GD::Polygon:
-    file: lib/GD/Polygon.pm
-  GD::Polyline:
-    file: lib/GD/Polyline.pm
-    version: '0.2'
-  GD::Simple:
-    file: lib/GD/Simple.pm

Failing to compile on Windows using VS2019

I've compiled Perl 5.38 with VS2019, then zlib, libpng, jpeglib and libgd with VS2019. I'd like to use the standard procedure for building GD, but it's failing at a few points:

Environment setup:

  • Start a fresh cmd.exe.
  • Pull VS2019 paths: "c:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat" x64 8.1
  • Set path to Perl and a few GNU tools conveniently included in git on Windows: set PATH=C:\xyzzy\perl_538\bin;%PATH%;c:\Program Files\Git\usr\bin
  • All the prerequisites are installed in C:\xyzzy\prerequisites.

Running Makefile.PL:

perl Makefile.PL --options="JPEG GIF PNG" --lib_gd_path=c:/xyzzy/prerequisites/lib --lib_png_path=c:/xyzzy/prerequisites --lib_jpeg_path=c:/xyzzy/prerequisites --lib_zlib_path=c:/xyzzy/prerequisites --ignore_missing_gd

Ends with an error:

Can't find c:/xyzzy/prerequisites/lib/pkgconfig/gdlib.pc.pc in any of /usr/local/lib/pkgconfig /usr/local/share/pkgconfig /usr/lib/pkgconfig /usr/share/pkgconfig
use the PKG_CONFIG_PATH environment variable, or
specify extra search paths via 'search_paths'
 at Makefile.PL line 557.
*** can not find package c:/xyzzy/prerequisites/lib/pkgconfig/gdlib.pc
*** check that it is properly installed and available in PKG_CONFIG_PATH
 at Makefile.PL line 557.

Why is it gdlib.pc.pc? The file gdlib.pc does exist in c:/xyzzy/prerequisites/lib/pkgconfig. If I copy gdlib.pc to gdlib.pc.pc, it still fails in the same way. By the way, --lib_gd_path has to end with "/lib" for this to work at all; using "\lib" fails in a different way.

I have to manually patch Makefile.PL with:

  • Edit Makefile.PL and add "return 0;" at top of sub try_to_autoconfigure so it's never run.

Then the above flags to Makefile.PL are fine. However, probably due to the way I've compiled libpng and zlib, I also need to manually patch:

  • Replace "-lpng" with "-lpng16_static"; replace "-lz" with "-lzlib".

Now a Makefile is successfully generated. Unfortunately, running:

nmake

Ends immediately with:

        "C:\xyzzy\perl_538\bin\perl.exe" lib/GD/Image_pm.PL lib/GD/Image.pm
Can't open perl script "lib": Permission denied
NMAKE : fatal error U1077: 'C:\xyzzy\perl_538\bin\perl.exe' : return code '0xd'
Stop.

Running that command in cmd.exe goes fine and produces the output Image.pm:

GD-2.79>"C:\xyzzy\perl_538\bin\perl.exe" lib/GD/Image_pm.PL lib/GD/Image.pm
Extracting Image.pm (with variable substitutions)

Then I can run nmake again, which ends with:

        "C:\xyzzy\perl_538\bin\perl.exe" "-Iblib\arch" "-Iblib\lib" bdf_scripts/bdf2gdfont_pl.PL bdf_scripts/bdf2gdfont.pl
Can't open perl script "bdf_scripts": Permission denied
NMAKE : fatal error U1077: 'C:\xyzzy\perl_538\bin\perl.exe' : return code '0xd'
Stop.

Run it manually:

GD-2.79>"C:\xyzzy\perl_538\bin\perl.exe" "-Iblib\arch" "-Iblib\lib" bdf_scripts/bdf2gdfont_pl.PL bdf_scripts/bdf2gdfont.pl
Extracting bdf2gdfont.pl (with variable substitutions)

Then run nmake again, and now the build succeeds.

For nmake test, I had to copy zlib.dll, libpng16.dll and libgd.dll to blib\arch\auto\GD, but that's fine. All the tests succeed, except:

t\windows_bmp.t ........... Can't locate object method "newFromBmp" via package "GD::Image" at t\windows_bmp.t line 11.
t\windows_bmp.t ........... 1/4 # Looks like your test exited with 255 just after 1.

That's because I omitted BMP support when configuring Makefile.PL. Looks like this test needs to be updated to not run if BMP support is excluded?

GD::Simple->fontMetrics doesn't seem to do what documentation says

The GD::Simple->fontMetrics() function doesn't seem to be coded in such a
way that it does what the documentation says. The documentation at
https://metacpan.org/pod/GD::Simple says that the metrics are defined in
terms of the rendering of the letters m, j, and d, but the code at
https://metacpan.org/release/GD/source/lib/GD/Simple.pm actually only
does test renderings of m and j, never d.

The documentation says that the lineheight is defined as
"the distance from the bottom of the 'j' to the top of the 'd'".
This sounds like the intention is to return the height of the string
'jd'. This would automatically be greater than the xheight. Actually
what it seems to calculate is the whitespace in the middle of "m\nm",
which is much smaller.

Here is some test code:

use GD::Simple;
use strict;
my $img = GD::Simple->new(100,100); # dummy height and width
my $font = $img->font('/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf',48);
my $metrics = $img->fontMetrics;
print "['xheight':",$metrics->{'xheight'},
",'ascent':",$metrics->{'ascent'},
",'descent':",$metrics->{'descent'},
",'lineheight':",$metrics->{'lineheight'},
",'leading':",$metrics->{'leading'},
"]\n"
;

The output is:

['xheight':38,'ascent':13,'descent':13,'lineheight':29,'leading':3]

I think the lineheight is wrong (too small), and the ascent is really
just a copy of the descent.

Here is a patch, which I think makes the code do what was intended and also clears up possible ambiguities in the documentation.

740,741c740
<   lineheight   the distance from the bottom of the 'j' to the top of
<                the 'd'
---
>   lineheight   the distance from the bottom to the top of the string 'jd'
743c742
<   leading      the distance between two adjacent lines
---
>   leading      the height of the empty space between two adjacent lines
771,773c770,773
<     my @mbounds   = GD::Image->stringFT($self->fgcolor,$font,
< 					$self->fontsize,0,
< 					0,0,'m');
---
>     my @mbounds   = GD::Image->stringFT($self->fgcolor,$font,$self->fontsize,0,0,0,'m');
>     my @jbounds   = GD::Image->stringFT($self->fgcolor,$font,$self->fontsize,0,0,0,'j');
>     my @dbounds   = GD::Image->stringFT($self->fgcolor,$font,$self->fontsize,0,0,0,'d');
>     my @mmbounds  = GD::Image->stringFT($self->fgcolor,$font,$self->fontsize,0,0,0,"m\nm");
775,778c775
<     my @jbounds   = GD::Image->stringFT($self->fgcolor,$font,
< 					$self->fontsize,0,
< 					0,0,'j');
<     my $ascent    = $mbounds[7]-$jbounds[7];
---
>     my $ascent    = $mbounds[7]-$dbounds[7];
780,786c777,780
< 
<     my @mmbounds  = GD::Image->stringFT($self->fgcolor,$font,
< 					$self->fontsize,0,
< 					0,0,"m\nm");
<     my $twolines  = $mmbounds[3]-$mmbounds[5];
<     my $lineheight  = $twolines - 2*$xheight;
<     my $leading     = $lineheight - $ascent - $descent;
---
>  
>     my $mm_height  = $mmbounds[3]-$mmbounds[5];
>     my $lineheight  = $xheight+$ascent+$descent;
>     my $leading     = $mm_height - 2*$xheight - $ascent - $descent;
788,791c782,785
< 		    descent    => $descent,
< 		    lineheight => $lineheight,
< 		    xheight    => $xheight,
< 		    leading    => $leading};
---
>                        descent    => $descent,
>                        lineheight => $lineheight,
>                        xheight    => $xheight,
>                        leading    => $leading};

use gdSetErrorMethod

overriding the libgd internal printf stderr,
and use it for perl warnings and errors.

POD improvement

man reports an error to split this. Little patch:

--- a/lib/GD.pm
+++ b/lib/GD.pm
@@ -1305,8 +1305,13 @@

 Creates a new palette image from a truecolor image.

-  samplefactor The quantization precision between 1 (highest quality) and 10 (fastest).
-  maxcolor     The number of desired palette entries.
+=over 4
+
+=item samplefactor: The quantization precision between 1 (highest quality) and 10 (fastest).
+
+=item maxcolor: The number of desired palette entries.
+
+=back

 This is the same as createPaletteFromTrueColor with the
 quantization method GD_QUANT_NEUQUANT. This does not support dithering.

new gd2 test errors

@eserte has a fedora system with gd 2.3.2 and GD.t still fails with GD-2.74:.
2.73 works fine

#   Failed test 'unable to generate comparison image for test 1: Can't locate object method "newFromGd2" via package "GD::Image" at (eval 16) line 1.
# '
#   at t/GD.t line 259.
Can't locate object method "newFromGd2" via package "GD::Image" at t/GD.t line 80.
# Looks like your test exited with 255 just after 3.
t/GD.t .................... Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 12/14 subtests 

Spelling errors

Hello,

little spelling errors:

--- a/lib/GD.pm
+++ b/lib/GD.pm
@@ -1432,7 +1432,7 @@
 =item B<$ok = $image-E<gt>contrast($contrast)>

 $contrast: a double value. The contrast adjustment value. Negative
-values increase, postive values decrease the contrast. The larger
+values increase, positive values decrease the contrast. The larger
 the absolute value, the stronger the effect.

 =item B<$ok = $image-E<gt>color($red,$green,$blue,$alpha)>
@@ -1487,7 +1487,7 @@
 format happens to be identical to the old-style MSDOS bitmap ".fnt"
 files, so you can use one of those directly if you happen to have one.

-For writing proportional scaleable fonts, GD offers the stringFT()
+For writing proportional scalable fonts, GD offers the stringFT()
 method, which allows you to load and render any TrueType font on your
 system.

seeking Dockerfile which can install GD.pm and Python and nginx

Hi,

I have a legacy CGI application which depends upon GD.pm. It also depends upon a quality Text To Speech command-line tool such as 'gTTS', and also nginx.

I've created a Dockerfile based upon Ubuntu 14.04 which can build the Perl that I need and also the Python that I need. But it lacks nginx. Starting with a modern base image such as 'ubuntu/nginx' yields build errors for GD.pm 'Unable to locate package libgd2-noxpm-dev'

Has anyone figured out how to install GD.pm using a modern base image? I'm not wedded to Ubuntu. My current Dockerfile appears below. As I mentioned, it builds fine, but lacks nginx.

# Set the base image to Ubuntu
FROM ubuntu:14.04

# File Author / Maintainer
MAINTAINER Jonathan Epstein <[email protected]>

# Update the repository sources list
RUN apt-get update

# Install compiler and perl stuff
RUN apt-get install --yes \
 build-essential \
 gcc-multilib \
 apt-utils \
 perl \
 expat \
 libexpat-dev

# Install perl modules
RUN apt-get install -y cpanminus

RUN cpanm CPAN::Meta \
 readline \
 Term::ReadKey \
 YAML \
 Digest::SHA \
 Module::Build \
 ExtUtils::MakeMaker

RUN apt-get install --yes \
 libarchive-zip-perl

# Install GD
RUN apt-get remove --yes libgd-gd2-perl

RUN apt-get install --yes \
 libgd2-noxpm-dev

RUN cpanm GD


# Copy-hacked from tomersha/docker-ubuntu-14.04-python-3.6.2
# PyEnv
ENV PYENV_ROOT /root/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
# Configure Python not to try to write .pyc files on the import of source modules
ENV PYTHONDONTWRITEBYTECODE true
ENV PYTHON_VERSION 3.6.2

RUN sudo apt-get update -q \
    && sudo apt-get install -y --no-install-recommends \
        build-essential \
        ca-certificates \
        curl \
        git \
        libbz2-dev \
        libreadline-dev \
        libsqlite3-dev \
        libssl-dev \
        zlib1g-dev

# Install pyenv and default python version
RUN git clone https://github.com/yyuu/pyenv.git /root/.pyenv \
    && cd /root/.pyenv \
    && git checkout `git describe --abbrev=0 --tags` \
    && sudo echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc \
    && sudo echo 'eval "$(pyenv init -)"'               >> ~/.bashrc

RUN pyenv install $PYTHON_VERSION
RUN pyenv local $PYTHON_VERSION

RUN pip install gTTS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.