PET::Util::Image

PET::Util::Image

Various methods that generate/handle images.  Use Image::Magick, we try to make that the only dependency.

Summary
PET::Util::ImageVarious methods that generate/handle images.
Functions
NAMEMandatory for all PET::Util classes.
createThumbnail (%p)Generate thumbnail given by parameters.
getCreateThumbUrl
thumbnail (%p)This creates an “img” tag, while resizing the given image.
captcha (%p)This creates an “img” tag holding a captcha.
cleanupCaptchaDir ($dir)Cleanup files in captcha dir.
captchaMD5 (%p)

Functions

NAME

sub NAME

Mandatory for all PET::Util classes.

createThumbnail (%p)

sub createThumbnail

Generate thumbnail given by parameters.

Parameters

srcsource file to image
dstdestination file to new image
maxwidthenclosing box, width
maxheightenclosing box, height

We use ABSOLUTE directories here.

Returns

hashref { ‘width’ ..  ‘height’ } on success or string (error string).

getCreateThumbUrl

sub getCreateThumbUrl

thumbnail (%p)

sub thumbnail

This creates an “img” tag, while resizing the given image.  It makes sense to call this from .pet files usually, as an HTML tag is returned.

Parameters

filesource image, can be BASEPATH relative or absolute
maxwidthtarget width (enclosing box)
maxheighttarget height (enclosing box)
formatoutupt file format, defaults to ‘png’
targetdirdefaults to ‘__thumbnails/’, and is $BASEPATH/html relative
assumetargetdirdefaults to 0 (false); if 1 (true), then does NOT create not-yet-existing target dir
alwayscreatedefaults to 0 (creates thumbnail on timestamps); otherwise always creates ig

Returns

A string, which is an <img /> attribute.  ‘src’ is set automatically, width and height is set.  Unknown input parameters are copyed “as-is”.

captcha (%p)

sub captcha

This creates an “img” tag holding a captcha.  It makes sense to call this from .pet files usually, as an HTML tag is returned.

widthtarget width (enclosing box)
heighttarget height (enclosing box)
formatoutupt file format, defaults to ‘png’
targetdirdefaults to ‘__captcha/’, and is $BASEPATH/html relative
assumetargetdirdefaults to 0 (false); if 1 (true), then does NOT create not-yet-existing target dir
stringthe text to write on the image (optional, see “maketext”; string overrides maketext)
maketextwrites random text on the image; parameter can be “digit-n” or “alpha-n”, where n stands for the number of characters ; digit means 0..9, while alpha means a..z0..9; n must be >1, <20
stylethe style to use when creating the captcha; defaults to ‘normal’ sessionvar = name of session variable to store captcha value (default ‘CAPTCHA’)
md5varhidden input type name where the captcha value will be put if you do not use “sessionvar”
md5keymd5 key for md5var
fontpathTrueType font path; absolute, or relative to BASEPATH

If md5var == ‘md’ and md5key = ‘abcde’, you will have

$md = md5_hex($md5key.$captcha.$md5key) ..<input type=”hidden” value=”$md” name=”md” /> ..right afterh the captcha image tag.  Put this in a form and you can check for the valid incoming captcha.

From UtilXmlMap you could call it like

<image:captcha width=”120” height=”45” format=”jpg” targetdir=”__captcha” maketext=”alpha-6” sessionvar=”CAPTCHA” fontpath=”fonts/Arial.ttf” />

cleanupCaptchaDir ($dir)

sub _cleanupCaptchaDir

Cleanup files in captcha dir.  Reads expiration from config.?

captchaMD5 (%p)

sub captchaMD5

Parameters

  • md5key
  • value
  • compareto => optional

Returns

string.

Base class for all Util modules.
sub NAME
Mandatory for all PET::Util classes.
sub createThumbnail
Generate thumbnail given by parameters.
sub getCreateThumbUrl
sub thumbnail
This creates an “img” tag, while resizing the given image.
sub captcha
This creates an “img” tag holding a captcha.
sub _cleanupCaptchaDir
Cleanup files in captcha dir.
sub captchaMD5
Close