Author image Martin Gillmaier


Catalyst::View::Image::Text2Image - View to create text into image AND render GD::Simple-images;


Catalyst::View::Image::Text2Image is a view that creates images using GD::Simple. You can set $c->stash->{Text2Image} to several options that will define your output. The "morph" Option lets your image stretch by length of given string and font-definition. Or you just create an image using GD::Simple and pass it to the view.


Create a Text2Image view:
 script/ view Image::Text2Image Image::Text2Image
Text2Image example:
  Your controller:

        sub Text2Image :Local {
                my ( $self, $c) = @_;
                $c->stash->{Text2Image}->{string}       ||= 'Done with Catalyst::View::Image::Text2Image';
                $c->stash->{Text2Image}->{x}            = 10; # doesn't matter in this case, might be just 1
                $c->stash->{Text2Image}->{y}            = 45;
                $c->stash->{Text2Image}->{font}         = 'Times New Roman';
                $c->stash->{Text2Image}->{fontsize} = '15';
                $c->stash->{Text2Image}->{bgcolor}      = 'black';
                $c->stash->{Text2Image}->{fgcolor}      = 'green';
                $c->stash->{Text2Image}->{moveTo}       = [0,44];
                $c->stash->{Text2Image}->{angle}        = -5;
                $c->stash->{Text2Image}->{morph}        = 1; ### Should the x value be adapted when text is too long?
                $c->stash->{Text2Image}->{clear}        = 1; ### define "clear" to make canvas-color = bgcolor !!
                $c->stash->{Text2Image}->{transparent}  = 'white'; # set color to become transparent
Example to process a pre-created image with GD::Simple:
  (this leaves you all the possibilities of GD::Simple)

  Your controller:
        sub Text2Image :Local {
                my ( $self, $c) = @_;
                my $img = GD::Simple->new(640, 480); 
                $img->rectangle(10, 10, 150, 150);
                $img->ellipse(50, 50);
                $img->font('Times New Roman');
                $img->string('Image processed by Catalyst::View::Image::Text2Image'); 
                $c->stash->{Text2Image}->{'img'} = $img;


The view is controlled by setting the following values in the stash:


(optional) Can contain a GD::Image object. If set, the view will not create an image but try to process/render this object. If not set, you need at least to provide "y","string", "font" and "fontsize".


The width (in pixels) of the image. Might be altered if option "morph" is set. Only considered if not $c->stash->{Text2Image}->{img}.


The height (in pixels) of the image. Mandatory if not $c->stash->{Text2Image}->{img}


The Text of the image. Only one line supported in this version. Mandatory if not $c->stash->{Text2Image}->{img}


(optional) Bool. Should the width of the image be adapted to the width of $c->stash->{Text2Image}->{string}? Note: The option "angle" isn't considered in "morph"-functionality, so your images may become to wide if you use "angle" and "morph" together. Only considered if not $c->stash->{Text2Image}->{img}


The font to use for the text. Mandatory if not $c->stash->{Text2Image}->{img}


The font to use for the text. Mandatory if not $c->stash->{Text2Image}->{img}

MORE Options...

More GD::Simple Options are just applied by values in the stash. Tested in this version are: bgcolor, fgcolor, moveTo, clear, transparent and angle. Refer to examples for more informations on that.

Image format

The generated images will always be produced in the PNG-Format.


GD::Simple Catalyst::View


Martin Gillmaier (MG), <gillmaus at>


Critics, requests, commercial support and training for this module is available: Contact "gillmaus at" for details.


Copyright (C) 2012 Martin Gillmaier (GILLMAUS).

This module is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory LICENSES.

This module is distributed in the hope that it will be useful, but it is provided "as is" and without any express or implied warranties.



        Main method of the view.


        Converts a texts into a png-image using GD::Simple;
        param: Hash-Ref of GD::Simple options (meaning: function=>value), for example: 
                                ### MUST-values:
                                x => 100,
                                y => 20, 
                                font => 'Times New Roman',
                                fontsize => 18,
                                string => 'Huhu..its me..your pic!',
                                ### OPTIONAL Values:
                                morph => 1,     # optional, will adapt x to string-width 
                                clear => '1',   # to set canvas-color=bgcolor. 
                                transparent => 'white' # make background transparent
                                ### other optional, GD::Simple Values:
                                fgcolor => 'black',
                                bgcolor => 'white',
                                angle => -5,
                                moveTo => [0,20] # Move pencil 
        return: GD image-Object