CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
opening images in perl

 



dimilinowski
Novice

Jul 31, 2008, 4:26 AM

Post #1 of 14 (1160 views)
opening images in perl Can't Post

#!\usr\bin\perl -w

open (MYPIC, "us.jpg") || die "Cannot open us.jpg: $!";
binmode (MYPIC);
print MYPIC "us.jpg";
close (MYPIC);



Filehandle MYPIC opened only for input at C:\Documents and Settings\Compaq_Owner\My Documents\Perl\test3.pl line 5--what does this mean?

Also, can you please guide me in a direction that I can learn more about manipulating image files with perl?



Thank you

Diane
Diane Milinowski


KevinR
Veteran


Jul 31, 2008, 7:07 PM

Post #2 of 14 (1155 views)
Re: [dimilinowski] opening images in perl [In reply to] Can't Post

Your code is trying to print "us.jpg" into a file named "us.jpg". But it can't because the filehandle MYPIC is opened for reading only. If you are trying to print out the data that is in "us.jpg" you do it like this:


Code
open (MYPIC, "us.jpg") || die "Cannot open us.jpg: $!"; 
binmode (MYPIC);
print <MYPIC>;
close (MYPIC);


But perl will not display an image if that is what you are trying to do, it has no concept of what an image file is. It would have to output the data to an application that knows how to handle a jpg image file.

To work with image files search CPAN for modules, I know there is GD and ImageMagick, there could be other modules.
-------------------------------------------------


agent
Novice

Aug 4, 2008, 12:53 AM

Post #3 of 14 (1142 views)
Re: [dimilinowski] opening images in perl [In reply to] Can't Post

check out this site:

http://www.imagemagick.org/script/perl-magick.php


(This post was edited by agent on Aug 4, 2008, 12:53 AM)


dimilinowski
Novice

Aug 9, 2008, 5:43 AM

Post #4 of 14 (1107 views)
Re: [agent] opening images in perl [In reply to] Can't Post

ImageMagick must already be installed on your system. Also, the ImageMagick source distribution for Windows 2000 is required.



How am I supposed to know this (if ImageMagick is installed on my system without searching for it?) ? Please tell me about both of those questions.

Thanks

Diane
Diane Milinowski


KevinR
Veteran


Aug 9, 2008, 10:42 AM

Post #5 of 14 (1103 views)
Re: [dimilinowski] opening images in perl [In reply to] Can't Post

If you are using activestate perl, open the activestate/activeperl folder that should be in your list of programs, START>>PROGRAMS or however it is for your version of Windows. Then double-click on "documentation" . That should open a web browser (the document is in html format) and display all the modules installed on the left as well as all the documentation that comes with activeperl. There is a wealth of information in those documents, you must learn how to read them and use them.
-------------------------------------------------


dimilinowski
Novice

Aug 11, 2008, 10:20 AM

Post #6 of 14 (1095 views)
Re: [KevinR] opening images in perl [In reply to] Can't Post

Why can't I backtick out of perl to have the image printed through Dos?

Diane
Diane Milinowski


dimilinowski
Novice

Aug 11, 2008, 10:27 AM

Post #7 of 14 (1093 views)
Re: [dimilinowski] opening images in perl [In reply to] Can't Post


Quote
Using Perl modules, which themselves use C libraries, from your C program



Is my c program something like picasa?

Thanks

Diane
Diane Milinowski


shawnhcorey
Enthusiast


Aug 11, 2008, 10:50 AM

Post #8 of 14 (1089 views)
Re: [dimilinowski] opening images in perl [In reply to] Can't Post


In Reply To
Why can't I backtick out of perl to have the image printed through Dos?

Diane


If you want to display an image, use the system() function:


Code
my $img = '/directory/image.png'; 
system( "firefox $img" );


Of course, replace firefox with the application you want to use.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


Johnny Utah
Novice

Aug 11, 2008, 12:47 PM

Post #9 of 14 (1086 views)
Re: [shawnhcorey] opening images in perl [In reply to] Can't Post

You might also want to read up on the GD module since GD is more likely to be installed on a Linux machine compare to ImageMagick:

http://search.cpan.org/~lds/GD-2.11/GD.pm

Although it appears as though you're using ActivePerl, so I guess it doesn't matter.
-----------------------------------------------------------------------------------------------------------------
Linux or Kubuntu user? http://kubuntuway.net


dimilinowski
Novice

Aug 17, 2008, 4:54 AM

Post #10 of 14 (1056 views)
Re: [shawnhcorey] opening images in perl [In reply to] Can't Post


Quote
my $img = '/directory/image.png';
system( "firefox $img" );



I'm assuming mine would be:



my $img = '/directory/image.png';
system( "internet explorer $img" );




Thanks

Diane



append: It works. Thank you so much. It's hard to believe Perl doesn't have codes for things like print $image; instead, but I did know about the system call and couldn't remember what it was.
Diane Milinowski

(This post was edited by dimilinowski on Aug 18, 2008, 3:35 AM)


dimilinowski
Novice

Aug 18, 2008, 3:47 AM

Post #11 of 14 (1039 views)
Re: [dimilinowski] opening images in perl [In reply to] Can't Post


In Reply To

Quote
Using Perl modules, which themselves use C libraries, from your C program



Is my c program something like picasa? Please answer this question.

Thanks

Diane

Diane Milinowski


dimilinowski
Novice

Aug 18, 2008, 4:00 AM

Post #12 of 14 (1038 views)
Re: [dimilinowski] opening images in perl [In reply to] Can't Post

Well, it's great that the pictures are opening and everything, but it's not really working the way that I expected or wanted it to. Here's the code:

my $img = 'C:\Documents and Settings\Compaq_Owner\My Documents\Perl\artwork.gif';
system( "explorer $img" );

print "What a great picture!\n";

my $img2 = 'C:\Documents and Settings\Compaq_Owner\My Documents\Perl\artwork2.gif';
system( "explorer $img2" );
print "Another awesome pic!\n";



I thought that the picture would open then the program would switch back to the command prompt, display the print value (which it doesn't), then open the 2nd picture, switch back to the command prompt and display the 2nd print value (and it doesn't). Not only that, but when the pictures are opened they open one after the other (very quickly) so that you actually don't have the opportunity to even look or scan the 1st pic, then the 2nd pic opens and stays open (which is good)--and that's not what the real problem is at this particular time, but that the program doesn't switch back to the command prompt without having to use the status bar in Windows to do so. I want it to go open pic, print words, open 2nd pic, print words, stay in c prompt under perl.



Thanks

Diane
Diane Milinowski


KevinR
Veteran


Aug 18, 2008, 11:41 AM

Post #13 of 14 (1033 views)
Re: [dimilinowski] opening images in perl [In reply to] Can't Post

Sorry, I have no idea how to help you. I don't understand what you are doing and I don't have any experience with using DOS to handle images.
-------------------------------------------------


shawnhcorey
Enthusiast


Aug 19, 2008, 5:21 AM

Post #14 of 14 (1026 views)
Re: [dimilinowski] opening images in perl [In reply to] Can't Post


In Reply To
I thought that the picture would open then the program would switch back to the command prompt, display the print value (which it doesn't), then open the 2nd picture, switch back to the command prompt and display the 2nd print value (and it doesn't). Not only that, but when the pictures are opened they open one after the other (very quickly) so that you actually don't have the opportunity to even look or scan the 1st pic, then the 2nd pic opens and stays open (which is good)--and that's not what the real problem is at this particular time, but that the program doesn't switch back to the command prompt without having to use the status bar in Windows to do so. I want it to go open pic, print words, open 2nd pic, print words, stay in c prompt under perl.


When you do a system() command, your Perl script is suspended until that command finishes. I suspect the reason the first image disappears so quickly is that explorer finds an error in the image. Open explorer and try viewing the image.

What you want to do is a fork. However, in Windows you have to go through the Win32 modules to do it. Since I'm not running Windows, I won't hazard guessing on how to do this. Try asking the perlmonks at www.perlmonks.org/

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives