Kevin Ryde
and 1 contributors


Test::Without::GD - pretend GD is without some file formats


 # command line
 perl -MTest::Without::GD=-gif,-png ...

 # or in script
 use Test::Without::GD '-jpeg';

 # or by method
 use Test::Without::GD;


This module mangles the GD module to pretend that some of its file formats are not available, as can happen if libgd was built without some of its supporting libraries, or configs set in the GD module, etc.

This can be used for testing to check how module code etc behaves without some of GD's things, or to exercise .t scripts to see that they skip checks for features not available.

The mangling is done by deleting or replacing selected GD::Image methods. Deleting uses Sub::Delete (perhaps that will change). There's an experimental no Test::Without::GD which tries to restore GD::Image back to normal operation. Is there any value in that? Usually the fakery will be for the duration of a script etc.


The module import recognises the following options


They correspond to the without_png() etc functions below. So for example to run a program pretending PNG is not available,

    perl -MTest::Without::GD=-png ...

Or when using the usual ExtUtils::MakeMaker test harness,

    HARNESS_PERL_SWITCHES="-MTest::Without::GD=-png" make test

The options can be applied from a script too (or the functions below used),

    use Test::Without::GD '-png';



Pretend that PNG, JPEG or GIF format is not available. This means removing the respective GD::Image methods,

    _newFromPng()    newFromPngData()   png()
    _newFromJpeg()   newFromJpegData()  jpeg()
    _newFromGif()    newFromGifData()   gif()

as is the case when GD is built without HAVE_PNG, HAVE_JPEG or HAVE_GIF.

The documented entrypoints newFromPng(), newFromJpeg() and newFromGif() in fact remain, but their underlying _newFromPng() etc are removed causing them to die.


Pretend that animated GIF support is not available. This means replacing GD::Image methods

    gifanimbegin(), gifanimadd(), gifanimend()

with instead

    sub {
      die "libgd 2.0.33 or higher required for animated GIF support";

as is the case when GD is built without HAVE_ANIMGIF.


Pretend that XPM format is not available. This means replacing GD::Image method


with instead

    sub {
      $@ = "libgd was not built with xpm support\n";

as is the case when GD is built without HAVE_XPM.


GD, Sub::Delete



Copyright 2011, 2012, 2015 Kevin Ryde

Test-VariousBits is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Test-VariousBits is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Test-VariousBits. If not, see