Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

GD loss of quality

by the_slycer (Chaplain)
on Apr 19, 2005 at 17:54 UTC ( #449356=perlquestion: print w/replies, xml ) Need Help??

the_slycer has asked for the wisdom of the Perl Monks concerning the following question:

I'm going to add a bit of explanation about why I'm in this bind before getting into the problem.

I'm working at a place where perl is being phased out - but oh so slowly. The reasons for it are many, and I won't go into it here. However, because it's being phased out, there's been no real drive to upgrade perl, and it's difficult at best to get support for newish things.

Having said that, I'm using perl 5.005_02 on redhat 6-2, and I cannot upgrade it. It's also going to be a next to impossible task to do what I really want to do, and install Image::Magick.

I'm stuck using GD (it's already installed) to resize an image, so quick test code looks like this:
open (TMP, ">/tmp/test.jpg"); my $file = upload('thefile'); my $image = GD::Image->newFromJpeg($file); my ($x, $y) = $image->getBounds(); my $new_image = new GD::Image(800, 600); $new_image->copyResized($image, 0, 0, 0, 0, 800, 600, $image->getB +ounds); binmode(TMP); print TMP $new_image->jpeg;
Which seems to be working fine-ish, it's creating 800x600 images for sure, but there is a drastic loss of image quality. And I don't mean the standard blockiness etc, I mean like a complete loss of color, so all I see are vague outlines of an image. This obviously is not acceptable, so, I'm trying desperately to discover why it's doing this.

The question is, has anybody run into this problem before? Why such a massive loss of quality? Secondly, are there any other potential modules that I can use other than Image::Magick (which rely's on drivers/software not currently installed on the redhat 6.2 boxes) and/or GD to perform this task? Or am I stuck going to bat to try and get ImageMagick installed?


On a semi related note, the *real* reason that I'm attempting to do this is so that all the image manipulation etc can happen "in memory". We've been running into a problem with a script that does this all by creating files on the machine, running a command on them, and then uploading the new file elsewhere. There are a lot of 0 byte files being created, and I suspect either NFS, or our clustering, or disk space as being the root cause. Has anybody run into the 0 byte problem before when accepting file uploads using an old version of CGI?

Note that the open & print to TMP is not actually necessary, nor will it be like this in the production code, this is just for me to view the images so I can run some tests. In actuality the file will be inserted into a BLOB in the database, hence the idea that we do this all without creating temp files...

Replies are listed 'Best First'.
Re: GD loss of quality
by ikegami (Pope) on Apr 19, 2005 at 18:25 UTC

    GD used to only support 256 colors. That would explain the loss of colours you encountered. Newer version of GD include "truecolor" arguments and methods which requests that GD doesn't reduce the images to 256 colours.

Re: GD loss of quality
by Joost (Canon) on Apr 19, 2005 at 17:58 UTC
      Again, the point is to get away from creating and/or using actual files, trying to do as much "in memory" as possible..
Re: GD loss of quality
by samtregar (Abbot) on Apr 19, 2005 at 20:40 UTC
    Has anybody run into the 0 byte problem before when accepting file uploads using an old version of CGI?

    No, but I have seen buggy CGI code that failed to properly check that the upload succeeded before writing out a file. Try this: go to your app and type some random text in the file upload field. Click the submit button. If a 0 byte file just appeared then you know what the problem is!


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://449356]
Approved by Joost
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2020-05-31 07:46 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (173 votes). Check out past polls.