LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-19-2011, 02:43 PM   #1
realbezo
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Rep: Reputation: 0
Post "hemera photo image" conversion script


Hello, i am a newbie at bash scripting and i have a question. I have many hpi image files in a directory and want to convert them png images.
I found on internet a perl script for this but it converts just single file and i cannot nor modify it neither pass it input file name and desired output file name for batch processing.
Could someone help me, i have more than tousand hpi image files...
( actually my problem is define 2 variables and pass them to the perl script recursively, it sounds simple but not for me)

the script is below;
---------------------
#! /usr/bin/perl

use Image::Magick; # AAM IT Solutions LTD,License::AGPLv3
my( $image, $mask, $input, $output, $jpg, $png, $line );
#input:hpi file,output: image file or none to display
$image = Image::Magick->new(magick=>'jpg');
#hpi stores the image in jpg
$mask = Image::Magick->new(magick=>'png');
#hpi stores the mask in png
($input, $output) = ($ARGV[0],$ARGV[1]);
open(I, "$input") || die("Error: Opening input argument.");
binmode(I);
while($line = <I>){ $_ .= $line;}
close(I);
($jpg, $png) = m/^.{32}(.*)(\211PNG.*)$/s;
$image->BlobToImage($jpg);
$mask->BlobToImage($png);
$image->Set(alpha=>Off);
$image->Composite(image=>$image,image=>$mask,compose=>CopyOpacity);
if ( "$output"){ $image->Write($output);}else{ $image->display();}
----------------------
and i run it with this command line,

"perl hpi2png.pl /home/user/path/input.hpi /home/user/path/output.png"
but how can i find filenames in a directory and pass all of the files recursively to this script in order to convert them quicker...
 
Old 12-19-2011, 03:04 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
that script uses imagemagick ,so....

have you tried the normal everyday use of imagemagick ?
Code:
convert name.hpi name.png
then if that works use the IM bulk "mogrify"
Code:
man mogrify
and
Code:
mogrify -format png *.hpi
 
Old 12-20-2011, 05:18 PM   #3
realbezo
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Hi, i didn't try it before you offered this simple command for converting hpi images but i tried now and it didn't work, i got this message

mogrify: no decode delegate for this image format `000204_4345_1092_oslp.hpi' @ constitute.c/ReadImage/530.
i think it is because of the structure of hpi image format, it is a special format.
i found a link about it (it is a cached webpage, it doesn't actually exist now, thanks to google)
http://webcache.googleusercontent.co...&client=ubuntu

i just need to repeat my command with all file names in a directory, rather than converting just a single image.
actually my question is not about a specific format, it is about bash scripting. in other words how can i make a list of files in a directory and use them.

"perl hpi2png.pl /home/user/path/input.hpi /home/user/path/output.png"
i need to change "input.hpi" with every file name and give a related output name instead of "output.png". my question is how can i recursively do it.
thanks in advance

Last edited by realbezo; 12-20-2011 at 05:19 PM.
 
  


Reply

Tags
bash scripting



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
[SOLVED] Errors executing shell script: "command not found" and "no such file or directory" eko000 Linux - Newbie 1 01-14-2011 07:54 AM
Rotate Image (Script) without changing "modified" date tg0000 Linux - General 2 11-20-2010 02:32 AM
seeking conversion to/from winXX tablet "journal" and X11 tablet "xournal" ink SaintDanBert Linux - Software 0 01-12-2010 05:14 PM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration