This is a discussion on Image Handling in PERL within the Perl forums, part of the Software Development category; hi all, here i have given some code for getting size of a image: It recognizes the most common image-...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| hi all, here i have given some code for getting size of a image: It recognizes the most common image-formats such as JPG, GIF, PNG, PSD, TIFF and plenty more. The interface is simple and will get you what you need with no trouble at all. #!/usr/bin/perl -w use strict; use Image::Size; # Just fetch the size my ($size_x, $size_y) = Image::Size::imgsize("test.jpg"); print "Image is: $size_y x $size_x (height x width)\n"; # HTML-friendly format my $size = Image::Size::html_imgsize("test.jpg"); print "Here is my image <img src=\"test.jpg\" $size>\n"; exit(); |
| Sponsored Links |
| |||
| hi all, The following functions are provided by the Image::Info module: image_info( $file ) image_info( \$imgdata ) image_info( $file, key => value,... ) This function takes the name of a file or a file handle as argument and will return one or more hashes (actually hash references) describing the images inside the file. If there is only one image in the file only one hash is returned. In scalar context, only the hash for the first image is returned. In case of error, and hash containing the "error" key will be returned. The corresponding value will be an appropriate error message. If a reference to a scalar is passed as argument to this function, then it is assumed that this scalar contains the raw image data directly. The image_info() function also take optional key/value style arguments that can influence what information is returned. image_type( $filename ) Returns a hash with only one key, file_type. The value will be the type of the file. On error, sets the two keys error and Errno. image_info( \$imgdata ) This function is a dramatically faster alternative to the image_info function for situations in which you only need to find the image type. It uses only the internal file-type detection to do this, and thus does not need to load any of the image type-specific driver modules, and does not access to entire file. It also only needs access to the first 32 bytes of the file. To maintain some level of compatibility with image_info, image_type returns in the same format, with the same error message style. That is, it returns a HASH reference, with the $type->{error} key set if there was an error. On success, the HASH reference will contain the single key 'file_type', which represents the type of the file, expressed as the type code used for the various drivers ('GIF', 'JPEG', 'TIFF' and so on). If there are multiple images within the file they will be ignored, as this function provides only the type of the overall file, not of the various images within it. This function will not return multiple hashes if the file contains multiple images. Of course, in all (or at least effectively all) cases the type of the images inside the file is going to be the same as that of the file itself. dim( $info_hash ) Takes an hash as returned from image_info() and returns the dimensions ($width, $height) of the image. In scalar context returns the dimensions as a string. html_dim( $info_hash ) Returns the dimensions as a string suitable for embedding directly into HTML or SVG <img>-tags. determine_file_format( $filedata ) Determines the file format from the passed file data (a normal Perl scalar containing the first bytes of the file), and returns either undef for an unknown file format, or a string describing the format, like "BMP" or "JPEG". |
| |||
| hi all, you can change your image format from JPEG to GIF or some other image format: Changing files from one format to another is quite easy with a little bit of Magick. In the example below a JPG image (test.jpg) is converted into a GIF-image (test.gif). To output in a different (ImageMagick supported) format, just change the "image->Set" line. #!/usr/bin/perl -w use strict; use Image::Magick; my $image = Image::Magick->new(); # To explicitly set image format use this instead: # my $image = Image::Magick->new(magick=>'JPEG'); my $x = $image->Read('test.jpg'); $x = $image->Set(magick => 'GIF'); $x = $image->Write('test.gif'); exit(); |
| |||
| hi all, Rotating an Image : In the example below an image is turned 90 degrees clockwise, wirtten to a file, turned another 90 degress and written to a file again. #!/usr/bin/perl -w use strict; use Image::Magick; my $image = Image::Magick->new(magick=>'JPEG'); my $x = $image->Read('test.jpg'); $x = $image->Rotate(degrees=>90); # 90 degress clockwise $x = $image->Write('test.90.jpg'); $x = $image->Rotate(degrees=>90); # Another 90 degress clockwise $x = $image->Write('test.180.jpg'); exit(); |
| |||
| hi all, Making thumbnails: you can automagically create thumbnails using ImageMagick function. #!/usr/bin/perl -w use strict; use Image::Magick; my $image = Image::Magick->new(magick=>'JPEG'); my $x = $image->Read('test.jpg'); $x = $image->Scale(width=>'50', height=> '50'); # The following should also work fine... # $x = $image->Scale(geometry=> '50x50'); $x = $image->Write('test.50x50.jpg'); exit(); |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Convert image to other image format using CODEC in .NET 3.0 | Mramesh | C# Programming | 0 | 02-07-2008 02:33 AM |
| Image handling in php | varghese | PHP Programming | 75 | 11-12-2007 08:58 PM |
| How to create an image from panel background Image | S.Vinothkumar | C# Programming | 1 | 10-22-2007 02:52 AM |
| File Handling in PHP | ragavraj | PHP Programming | 20 | 09-12-2007 10:46 PM |
| How to set Perl Interpreter within perl script | sivaramakrishnan | Perl | 1 | 07-19-2007 05:45 AM |