PET::Util::Image |
Various methods that generate/handle images. Use Image::Magick, we try to make that the only dependency.
| PET:: | Various methods that generate/handle images. |
| Functions | |
| NAME | Mandatory 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) |
sub NAME
Mandatory for all PET::Util classes.
sub createThumbnail
Generate thumbnail given by parameters.
| src | source file to image |
| dst | destination file to new image |
| maxwidth | enclosing box, width |
| maxheight | enclosing box, height |
We use ABSOLUTE directories here.
hashref { ‘width’ .. ‘height’ } on success or string (error string).
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.
| file | source image, can be BASEPATH relative or absolute |
| maxwidth | target width (enclosing box) |
| maxheight | target height (enclosing box) |
| format | outupt file format, defaults to ‘png’ |
| targetdir | defaults to ‘__thumbnails/’, and is $BASEPATH/html relative |
| assumetargetdir | defaults to 0 (false); if 1 (true), then does NOT create not-yet-existing target dir |
| alwayscreate | defaults to 0 (creates thumbnail on timestamps); otherwise always creates ig |
A string, which is an <img /> attribute. ‘src’ is set automatically, width and height is set. Unknown input parameters are copyed “as-is”.
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.
| width | target width (enclosing box) |
| height | target height (enclosing box) |
| format | outupt file format, defaults to ‘png’ |
| targetdir | defaults to ‘__captcha/’, and is $BASEPATH/html relative |
| assumetargetdir | defaults to 0 (false); if 1 (true), then does NOT create not-yet-existing target dir |
| string | the text to write on the image (optional, see “maketext”; string overrides maketext) |
| maketext | writes 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 |
| style | the style to use when creating the captcha; defaults to ‘normal’ sessionvar = name of session variable to store captcha value (default ‘CAPTCHA’) |
| md5var | hidden input type name where the captcha value will be put if you do not use “sessionvar” |
| md5key | md5 key for md5var |
| fontpath | TrueType font path; absolute, or relative to BASEPATH |
$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.
<image:captcha width=”120” height=”45” format=”jpg” targetdir=”__captcha” maketext=”alpha-6” sessionvar=”CAPTCHA” fontpath=”fonts/Arial.ttf” />
Mandatory for all PET::Util classes.
sub NAME
Generate thumbnail given by parameters.
sub createThumbnail
sub getCreateThumbUrl
This creates an “img” tag, while resizing the given image.
sub thumbnail
This creates an “img” tag holding a captcha.
sub captcha
Cleanup files in captcha dir.
sub _cleanupCaptchaDir
sub captchaMD5