I am trying to use Win32-IE-Mechanize to open a webpage that has an image in it that is generated by PHP.

I have written a script to save the image, but it winds up saving another html page that has a link to the image - here is the perl:

use Win32::IE::Mechanize; use Time::HiRes; $ie = Win32::IE::Mechanize->new( visible => 1 ) ; $ie->get( 'http://localhost/image/myimage.php' ) ; while($ie->{agent}->Document->readyState !~ /complete/i){ sleep(0.1); +} $content = $ie->content; save_image($content); sub save_image { my ($content) = @_; open my $out_fh, ">", "image.png" or die $!; binmode $out_fh; print $out_fh $content; close $out_fh; }


here is the php myimage.php that generates the image:
<?php $my_img = imagecreate( 200, 80 ); $background = imagecolorallocate( $my_img, 0, 0, 255 ); $text_colour = imagecolorallocate( $my_img, 255, 255, 0 ); $line_colour = imagecolorallocate( $my_img, 128, 255, 0 ); imagestring( $my_img, 4, 30, 25, "test image", $text_colour ); imagesetthickness ( $my_img, 5 ); imageline( $my_img, 30, 45, 165, 45, $line_colour ); header( "Content-type: image/png" ); imagepng( $my_img ); imagecolordeallocate( $line_color ); imagecolordeallocate( $text_color ); imagecolordeallocate( $background ); imagedestroy( $my_img ); ?>


and the original html page that displays the image:
<img src="myimage.php" alt="Image created by a PHP script" width="200" + height="80">

when I try to save the png image i get a png file that contains the following html
<HTML><HEAD></HEAD> <BODY leftMargin=0 scroll=no topMargin=0><EMBED height="100%" type=ima +ge/x-png width="100%" src=http://localhost/image/myimage.php fullscre +en="yes"></BODY></HTML>

so instead of saving the png image, I am getting HTML with a link the png image.

any ideas???

In reply to Save PHP-generated image with Win32 IE Mechanize by casimo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.