![]() |
![]() |
||||||
|
|||||||
POD documentation > Content Management > Image.pm posted on 3:13 PM, July 12, 2009
ExSite::Image - image managerProvides a few basic image management tools for the ExSite CMS. This is just a simple wrapper/API to whatever underlying image processing tools are going to do the heavy lifting, so it is easy to replace or extend with more powerful tools if needed. This version tries to use Image::Info for fetching image attributes, and the convert shell command for modifying the image itself. NB: the convert command is part of the ImageMagick suite; so we could have just used the ImageMagick perl module instead. But the functions we require are relatively simple, so the massive ImageMagick module is a bit redundant for now. To start working with a new image: my $img = new ExSite::Image($name,$rawdata); # OR To get the image attributes: my $info = $img->info; # $info is a hash ref To get the image size: my ($x,$y) = $img->dim; There are two ways to change the image size: To scale the image size: my $stat = $img->scale(500,500,$flag); # $flag > 0 scale up to that size, if smaller To scale the image to exactly the passed dimensions (the edges may get cropped to achieve the new dimensions without distorting the original image): my $imgdata = $img->scale_crop($x,$y); To thumbnail an image (preserve aspect ratio): my $stat = $img->thumb; # equivalent to $img->scale(100,100,-1); To get a square thumbnail (some cropping may be involved): my $imgdata = $img->square_thumb($width); To force an exact resize without regard to aspect ratio, use resize: my $stat = $this->resize($newwidth,$newheight); my $imgdata = $img->get; To get image data in exsite binary file encoding format: my $imgdata = $img->encode; To get the size of the image data in bytes: my $nbyte = $img->size; To shrink the file size of the image: $img->shrink(%opt); You can pass the following options in the hash: In all cases, the quality of the image is set to 75% (mostly
meaningful for JPGs), which will help shrink high-quality photos for
web presentation without appreciable loss in quality. With
Preparation of Images for the WebOnly GIF, PNG, and a subset of JPG images are widely accepted by browsers. Some JPGs are not web-friendly (namely ones with CMYK color encoding). To test whether this is a web-ready image: if ($img->web_ready) { ...
If the image is not web ready, then you can convert it to a web-ready JPG format: $img->jpeg(); This can be used as a function call, if you prefer; it returns the number of bytes in the new JPEG file if the conversion succeeded, 0 if not. The other thing that is often needed to prepare web images is just to scale them to a reasonable size. Images from digital cameras tend to be too large for web display, and images may also be large in terms of file size due to high quality settings, embedded profiles, and other factors. You can use the scale function to force the image dimensions down to a specific size, or you can use the shrink function to set upper limits on both image dimensions and file size: $img->shrink( If an image was uploaded in a non-lossy format like PNG, then the file size might be shrinkable much farther if converted to a JPEG first. However, for some types of line art, PNG and GIF can give excellent compression. |
Recent ArticlesDocumentation Topicsbest practices (5)
content management (12)
data handling (7)
fundamentals (3)
google (5)
graphic design (21)
html formatting (7)
IT (8)
plug-in modules (28)
POD (32)
programming (48)
RSS (3)
security (3)
SEO (3)
visual tutorial (29)
web protocols (9)
|