Re: Understanding GD.pm
by robartes (Priest) on Oct 31, 2002 at 07:59 UTC
|
You should try checking the error log of your browser - it should tell you what (if anything) happened and where things started careening off track.
CU Robartes- | [reply] |
Re: Understanding GD.pm
by tomhukins (Curate) on Oct 31, 2002 at 11:30 UTC
|
Have you read the existing nodes about GD on Perl Monks? You might find some useful information there.
From a quick glance at your code, I notice you don't use strict or CGI. You might find several of the Tutorials here useful, such as use CGI or die; and CGI Help Guide.
Although you check for errors when opening file.jpg, you don't check for errors elsewhere, such as when you call GD::Image->newFromJpeg(). You have no way of knowing whether these methods succeed or fail.
| [reply] [d/l] |
|
|
Thanks,
GD is not the preferred library for image manipulaiton within PerlMonks forums or anywhere else. Image::Magik is. Unfortunatly, I am not able to use it.
I am not sure that use CGI; is required when only using the GD library. I have not needed to use it in the past with GD.
But I added it to the script. No change.I get a blank page.
The error checking was a good point. I added it with no change.I get a blank page.
Do you mean use diagnostics or warnings?
As far as strict goes it did show premature script headers.
But I cant find what is causing this..
Thanks again
Cal
| [reply] [d/l] |
|
|
GD is not the preferred library for image manipulaiton within PerlMonks forums or anywhere else.
There's more than one way to do it. Sometimes you might prefer GD to complete a task, other times you might prefer ImageMagick.
I am not sure that use CGI; is required when only using the GD library.
Your code contains the line print "Content-type: text/html\n\n"; which suggests you are writing a CGI script. This suggestion has nothing to do with GD: when writing a CGI script, use CGI.
The error checking was a good point. I added it with no change.I get a blank page.
As I mentioned earlier, read the Tutorials that seem relevant. Learn about other debugging techniques that might help you find the cause of this problem.
If you haven't done so already, read the GD documentation carefully to ensure your code uses it correctly.
| [reply] [d/l] [select] |
Re: Understanding GD.pm
by strider corinth (Friar) on Oct 31, 2002 at 15:08 UTC
|
In addition to the above comments, it's worth noting that simpler is usually better. I know you copied the script from a CGI, but it would probably benefit you to remove the CGI code and run it straight from the terminal, if you have that option. With strict and warnings on, you'll see a lot of useful output that way. Apart from that, it may be your web server's fault that you're not seeing the print statement. (It could also be your browser; did you look at the source of the blank page?) Cutting those possible sources of error out of the loop might save you a few headaches.
Either way, even if the print statement hasn't shown up, the jpeg may have been saved to disk. From the code you posted, it will never be displayed on the web page, even if the script runs successfully. It sounds like you're looking for the output on the web page itself. Have you checked the filesystem to see if it's there?
--
Love justice; desire mercy.
| [reply] |
|
|
Thanks so much,
I wish I was able to run a command line.
I agree strict and warnings should always be used.
The jpg did not save to disk. That was the first thing I checked for.
I really did not see any code in my post that should print the new or old jpg to screen.
Cal
| [reply] |
|
|
Ouch. That's a tough case to be in.
If the code you posted was the whole thing, may I suggest a few additions? If you add these lines to the end:
close FILE;
print "<img src = 'test.jpg'></body></html>\n\n";
and this to the beginning, after the header:
print "<html><head><title>Test page</title></html><body>\n";
That will make your output an actual HTML page, and make your Perl just a tough more correct. I don't honestly think that's your problem, but it wouldn't hurt to make sure that it isn't.
--
Love justice; desire mercy.
| [reply] [d/l] [select] |
|
|
|
|
|
|
Re: Understanding GD.pm
by l2kashe (Deacon) on Oct 31, 2002 at 14:55 UTC
|
The posts before say it fine. There just isn't enough error checking. It really is a good practice to get into, even for simple code. You never know when you might use it again, and when that time comes, people generally think "I made sure that was fine back then so it's ok to use it now." And they get burned because of it....
/* And the Creator, against his better judgement, wrote man.c */ | [reply] |
Re: Understanding GD.pm
by fireartist (Chaplain) on Oct 31, 2002 at 16:59 UTC
|
I think you're a little confused about what you're trying to do.
If you wish to view the jpg image in your web-browser, you shouldn't
open or print to the FILE file handle.
You also cannot print text and binary data at the same time.
If you just want to view the jpeg in the browser, change
print "Content-type: text/html\n\n";
to
print "Content-type: image/jpeg\n\n";
and then
print $newimage->jpeg;
Also don't print any text or anything else.
If you want to output a HTML page which contains an image, you must use the script to print out the HTML code, and in that code the IMAGE src href must point to a CGI which outputs only the image data (as above).
Hope this helps! | [reply] [d/l] [select] |
|
|
Thanks for your help,
I have commented out any reference to print "Content-type: text/html\n\n";
replacing the initial print header with print "Content-type: image/jpeg\n\n";
using the line print $newimage->jpeg;
Now I get an empty image with the "X"
| [reply] [d/l] [select] |
|
|
You said before that the script seemed to be stopping after you tried to make the new image from the old jpeg, which lines up with what you're seeing now. I'd suggest switching back to HTML output and changing the line to this:
my $srcimage = GD::Image->newFromJpeg("churchmiddle.jpg") || print "GD
+::Image->newFromJpeg('churchmiddle.jpg') failed: $!<br>\n";
That should tell you a little more about what's going on.
--
Love justice; desire mercy.
| [reply] [d/l] |
|
|
|
|
|