Generating page from image - part two

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
LVL 9
Rowby GorenAsked:
Who is Participating?
 
wilcoxonConnect With a Mentor Commented:
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
 
TintinCommented:
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
 
Rowby GorenAuthor Commented:
Hi,

Thanks,

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

Rowby
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
Rowby GorenAuthor Commented:
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
 
Rowby GorenAuthor Commented:
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
 
wilcoxonCommented:
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
 
wilcoxonCommented:
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
 
wilcoxonCommented:
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
 
Rowby GorenAuthor Commented:
Hi Got it. Along with your Ooops comment.

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

Thanks again.

Rowby
0
 
Rowby GorenAuthor Commented:
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
 
Rowby GorenAuthor Commented:
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
 
Rowby GorenAuthor Commented:
I have asked tech support at the hosting company to reinstall the script and look into the ownership issue.

Will report back here.
0
 
Rowby GorenAuthor Commented:
Adding the snippit.  Will report back
0
 
Rowby GorenAuthor Commented:
Thanks  Sorry for the delay in awarding these points.  I just happened to come back and noticed this question "unawarded".

Rowby
0
All Courses

From novice to tech pro — start learning today.