Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Generating page from image - part two

Posted on 2003-03-31
14
Medium Priority
?
203 Views
Last Modified: 2010-03-05
Please see this recently answered question:

http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_20566985.html

I need to incorporate some additional HTML code within the perl script.  I realize there are ways for format HTML within Perl, but I don't know how to do it.  Below is a link to an approximation of what I need added to the perl script.  (I know the page may seem oddly arranged, but that will be taken care of by a specially sized popup window which is being taken care of by javascript -- being answered right now on another part of experts exchange (all my friends thing *I* am the expert hee hee!)

I could post the source code here of the below link but rather than clutter up the question, I inviteyou to view the source code after clicking on the following link:

http://www.rcsoundselectronics.com/content/samplepopup.html

Thanks again all!

Rowby
0
Comment
Question by:Rowby Goren
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
14 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 8243334
I'm not a big fan of generating HTML via the CGI module.  Much better to use a templating system, or just output it directly, eg:

#!/usr/bin/perl

print <<HTMLSTUFF;
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<p align="center"><img src="images/just-arrived.gif" width="94" height="112">
</p>
<p align="center"><img src="../store/images_products/l570CDCX927-f.jpg" width="200" height="67">
</p>
<p align="center">
  <input type="button" value="Close this window" onClick="window.close()">
</p>
<p align="center"><b><font face="Arial, Helvetica, sans-serif" size="2">By the
  way I think when you click the &quot;close this window&quot; button<br>
  it might close the Experts Exchange broswer window too!</font></b></p>
<p align="center">&nbsp;</p>
</body>
</html>
HTMLSUFF
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 8243344
Hi,

Thanks,

Looks like this would work.  I'm off to sleepy and will try it out in the a.m.

Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 8243362
HI again,

Rereading the code in the previously answered question, I need to add that the key perl elements of the following need to be incorporated into the solution.

I like the idea of generating HTML  code in the way Tintin suggeseted, but it still needs to do some steps as you can see in the following working code from this recently answered question:

http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_20566985.html

Below is the working perl script:


#!/usr/local/bin/perl-T

use strict;
use warnings;
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);

# replace strings in the below code with meaningful values
# for example, the_directory_where_the_images_are needs to be the real path
# to the images

opendir DIR, '/home/sites/site2/web/rc-images' or die $!;
while (my $file = readdir DIR) {
  next unless $file =~ /^(.*)\.(?:jpg|gif|png)$/;
# make sure it is an image
  my $base = $1;
  open HTML, ">/home/sites/site2/web/rc-images/$base.html" or die $!;
  print HTML start_html,
# html headers
      br, br, br, br
# space down some vertically (4 lines)
      div({-align => 'center'},
# center horizontally
          img({-src => $file}),
# change $file to "path_to_images/$file" if images are in different directory than html
          $file),
      end_html;
# end tags
  close HTML;
}
closedir DIR;
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Author Comment

by:Rowby Goren
ID: 8245824
Hi Tintin (or anyone who wants to jump in here) --

Just checking if you read my previous comment.  The HTML page needs to incorporate (in some way) wilcoxon's code from http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_20566985.html

... which goes thorugh the directory and makes html pages from the names of jpg/gif files that are in that directory.

Perhaps direclty or as you suggest through a template (I'm just a copy and paste-modifier of perl, not a perl writer, so I'm a bit in the dark here.)

I will be happy to split the points if appropriate.

Thanks

Rowby
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 8246528
This assumes that ../store/images_products/l570CDCX927-f.jpg in the example page is what should be the product image from the code I previously did.  If not, it's fairly easy to rearrange yourself or I can help you.

Using CGI to generate the HTML:

#!/usr/local/bin/perl-T

use strict;
use warnings;
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);

opendir DIR, '/home/sites/site2/web/rc-images' or die $!;
while (my $file = readdir DIR) {
    next unless $file =~ /^(.*)\.(?:jpg|gif|png)$/;  # make sure it is an image
    my $base = $1;
    open HTML, ">/home/sites/site2/web/rc-images/$base.html" or die $!;
    print HTML start_html({-bgcolor => '#FFFFFF', text => '#000000'},
        p({-align => 'center'}, img({-src => 'images/just-arrived.gif', -width => '94', -height => '112'})),
        p({-align => 'center'}, img({-src => $file}), $file),
        p({-align => 'center'}, input({-type => 'button', -value => 'Close this window', onClick => 'window.close()'})),
        p({-align => 'center'}, b(font({-face => 'Arial, Helvetica, sans-serif', size => '2'}, 'By the way I think when you click the &quot;close this window&quot; button<br>it might close the Experts Exchange browser window too!'))),
        p('&nbsp;'),
        end_html;
    close HTML;
}
closedir DIR;

Not using CGI to generate the HTML:

#!/usr/local/bin/perl-T

use strict;
use warnings;
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);

opendir DIR, '/home/sites/site2/web/rc-images' or die $!;
while (my $file = readdir DIR) {
    next unless $file =~ /^(.*)\.(?:jpg|gif|png)$/;  # make sure it is an image
    my $base = $1;
    open HTML, ">/home/sites/site2/web/rc-images/$base.html" or die $!;
    print HTML <<HTMLSTUFF;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p align="center"><img src="images/just-arrived.gif" width="94" height="112"></p>
<p align="center"><img src="$file">$file</p>
<p align="center"><input type="button" value="Close this window" onClick="window.close()"></p>
<p align="center"><b><font face="Arial, Helvetica, sans-serif" size="2">By the way I think when you click the &quot;close this window&quot; button<br>it might close the Experts Exchange browser window too!</font></b></p>
<p>&nbsp;</p>
</body>
</html>
HTMLSTUFF
    close HTML;
}
closedir DIR;
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 8246559
I did not put the height and width in for the product image as I'm guessing it may vary.  If it will always be the same size then change:

img({-src => $file}) into img({-src => $file, -width => 200, -height => 67)

or

<img src="$file"> into <img src="$file" width="200" height="67">
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 8246570
Oops.  On the second code example above, you can remove the "use CGI qw(:all);" line as it does not use CGI to generate the HTML.
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 8246695
Hi Got it. Along with your Ooops comment.

Will be trying it out later today and will report back.

Thanks again.

Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 8246886
Hi

I'm getting this error message from the error log.  I'm guessing it may have something to do with a permissions/ownership issue with this particular host, and may have to have them adjust ownership.

But first here is the version of the script (copy and paste) I am using.  (foobar replaces actual domain name)

===========  Copy and paste starts next ======
#!/usr/local/bin/perl-T

use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);

opendir DIR, '/home/sites/site2/web/rc-images' or die $!;
while (my $file = readdir DIR) {
   next unless $file =~ /^(.*)\.(?:jpg|gif|png)$/;  # make sure it is an image
   my $base = $1;
   open HTML, ">/home/sites/site2/web/rc-images/$base.html" or die $!;
   print HTML <<HTMLSTUFF;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p align="center"><img src="http://www.foobar.com/content/images/rc-mini-logo1.gif" width="80" height="100"></p>
<p align="center"><img src="$file">$file</p>
<p align="center"><input type="button" value="Close this window" onClick="window.close()"></p>
<p align="center"><b><font face="Arial, Helvetica, sans-serif" size="2">By the way I think when you click the &quot;close this window&quot; button<br>it might close the Experts Exchange browser window too!</font></b></p>
<p>&nbsp;</p>
</body>
</html>
HTMLSTUFF
   close HTML;
}
closedir DIR;


============  End of copy and paste ends above =====

Tue Apr  1 11:42:14 2003] [error] [client 66.51.217.94] Premature end of script headers: /home/ELErcs/www/cgi-bin/rowby-scripts/createhtml.cgi
[Tue Apr  1 11:42:52 2003] [error] (2)No such file or directory: exec of /home/ELErcs/www/cgi-bin/rowby-scripts/createhtml-new.cgi failed
[Tue Apr  1 11:42:52 2003] [error] [client 66.51.217.94] Premature end of script headers: /home/ELErcs/www/cgi-bin/rowby-scripts/createhtml-new.cgi
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 8247024
Hi

I'm noticing that the owners of the HTML pages are owned by "nobody".  That I think is causing the problem. Can you set the perl script so that they are owned by FOOBAR?

I have a feeling you can't do this in perl, but maybe I am wrong.

Thanks

Rowby
0
 
LVL 26

Accepted Solution

by:
wilcoxon earned 1000 total points
ID: 8247776
I don't think you can directly set that in perl.  That's what my previous (last question) code did.  The end of the script would look like:

close HTML;
system 'chown', 'FOOBAR', "/home/sites/site2/web/rc-images/$file";
}
closedir DIR;

As to the "premature end of headers", I think that means that it's complaining because there is no output going back to the browser.

Add this after "closedir DIR" (eg very end of the script).

print <<HTMLSTUFF2;
Content-Type: text/html; charset=ISO-8859-1
<html>
<body>
<br><br><br>
<div align="center">script finished.</div>
</body>
</html>
HTMLSTUFF2
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 8247793
I have asked tech support at the hosting company to reinstall the script and look into the ownership issue.

Will report back here.
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 8247906
Adding the snippit.  Will report back
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 9436302
Thanks  Sorry for the delay in awarding these points.  I just happened to come back and noticed this question "unawarded".

Rowby
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question