General discussion

Locked

Perl scripting in linux

By eric_7178 ·
Hello All,
I am currently learning perl for professional reasons.
Is there any way to create a script that will read a jpeg file and print the file attributes
file size, resolution etc.

any examples or tutorials will be greatly appreciated.

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

call the file command

by Roger In reply to Perl scripting in linux

The command "file filename" will display specifics about the file. For .jpg files it reports the file's resolution in DPI as the 10th and 12th fields in the output if using whitespace as delimeters. The command "ls -l filename" will give the file size in bytes as the 5th field if using whitespace as delimeters. All you need to do in perl is execute these 2 commands and extract the desired information from their outputs. Sorry I can't be more helpful as I am just beginning to explore perl for web page design.

To get you started here's a small perl script

#!/usr/bin/perl
system "file /etc/passwd > perltest";
system "ls -l /etc/passwd >> perltest";
system "cat perltest";

Be sure to chmod the file first to make it executable (r-x or rwx) before testing.

This script redirects the output of the file and ls commands into a file named perltest (empties the file first if it exists) and then copues the contents of the file to the screen. You could open the file and parse it looking for the specific data you are interested in.

Good Luck!

Collapse -

Check out CPAN

by nick In reply to Perl scripting in linux

There is a module called image-info I believe
that will allow you to extract all kinds of
information. Image::Magick will allow you to do
the same and manipulate the image as well.

Back to Linux Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums