Image Resize Quality

257 views
Skip to first unread message

Completely Free Dating - Andrew

unread,
Jul 19, 2009, 9:54:10 AM7/19/09
to Railo
Hi,

I'm having some issues with quality of images produced by ImageResize.
I have source image that is 412px wide and good quality and I'm
resizing it to 250px wide using the following code:

<cfimage source="#str_FilePath##variables.str_filename#"
name="theImage">
<cfset tmp = ImageResize(theImage, "250", "", "highestQuality")>
<cfimage action="write"
source="#theImage#"
destination="#str_FilePath#page_#variables.str_filename#"
overwrite="yes"
quality="1">

This in theory should generate a high quality 250px wide image,
however the resulting image is all pixelated and blurry.

Can some let me know what I'm doing wrong.

Thanks.

Andrew.

Dave

unread,
Jul 19, 2009, 10:28:54 AM7/19/09
to ra...@googlegroups.com
Have you tried slimming your code?

So you set your image and then do nothing with it and then resize the
image and then write the image.
It might be that last write image. Every time you write over an image
it losses quality.

You can get it down to 1 action like and you dont need
"highestQuality" since it's the default

<cfimage action="resize" height=" " width="250" source="#theImage#"
destination="#str_FilePath#page_#variables.str_filename#"
overwrite="yes">

So If I upload a photo to your site and its 150 px your code is going
to enlarge it which will screw it up as well.

Completely Free Dating - Andrew

unread,
Jul 19, 2009, 12:19:52 PM7/19/09
to Railo
Hi,

That is the same as I had it originally and it was terrible as well, I
was trying to make it better by changing the interpolation to see if a
different setting would help, which is how I ended up with the code I
had, anyway, the long and short is, the original is always larger then
250px wide and the resulting output image is always 250px wide and the
quality is terrible. I have been playing with settings for hours now
and it doesn't seem to matter what I do, the output is terrible. I
have changed it to call ImagemagicK convert using a cfexecute and the
quality is just fine.

Guess the resize engine in Railo just isn't up to much or there is
some other parameter set to a bad default that can't be changed via
the parameters. There was a very similar problem during the first
beta's of CF8 and I think I remember Adobe was originally using the
image manipulation built into Java and they ended up scrapping it and
replacing it with a different image manipulation library to improve
the quality of the output.

Kind regards,

Andrew.

Pierre-Olivier Chassay

unread,
Jul 19, 2009, 1:25:11 PM7/19/09
to ra...@googlegroups.com
Just my 2 cent on this problem
did you try to convert the image before to a bmp make the resize and
convert it again to jpg.

Some person find this solution
http://www.coldfusionjedi.com/index.cfm/2009/7/15/Error-resizing-a-JPG-with-ColdFusion
Look at the comments part.

Regards,
Pierre-Olivier

Completely Free Dating - Andrew

unread,
Jul 19, 2009, 2:27:32 PM7/19/09
to Railo
Ok, maybe I'm getting something wrong here, but when I try and do what
the CFJedi posts suggestion about converting to BMP I get an error
trying to write the BMP:

<cfimage source="#str_FilePath##str_filename#" name="theImage">
<cfimage action="write" source="#theImage#"
destination="#str_FilePath#temp.bmp" overwrite="yes">
<cfimage source="#str_FilePath#temp.bmp" name="theImage">

The error (and part of the stack trace) I get is:

No compression type set!
at javax.imageio.ImageWriteParam.setCompressionQuality(Unknown
Source):-1
at railo.runtime.img.Image.writeOut(Image.java:854):854
at railo.runtime.img.Image.writeOut(Image.java:800):800
at railo.runtime.img.Image.writeOut(Image.java:786):786
at railo.runtime.tag.Image.doActionWrite(Image.java:466):466
at railo.runtime.tag.Image.doStartTag(Image.java:322):322

I'm guessing this is a Railo bug.

Kind regards,

Andrew.

On Jul 19, 6:25 pm, Pierre-Olivier Chassay <moo...@googlemail.com>
wrote:
> Just my 2 cent on this problem
> did you try to convert the image before to a bmp make the resize and
> convert it again to jpg.
>
> Some person find this solutionhttp://www.coldfusionjedi.com/index.cfm/2009/7/15/Error-resizing-a-JP...

Completely Free Dating - Andrew

unread,
Jul 19, 2009, 3:04:18 PM7/19/09
to Railo
Ok, bit more investigation and I have found a solution. The problem
appears to be the source file is 300 DPI and Railo is resampling it
down to 72 DPI and resizing at the same time. If I read the 300 DPI
file in and then save it to the disk and then read the temp file in
and resize it and save it back to the disk the resulting image is good
quality.

However I did have to do it using the ImageResize tag (with the
interpolation set to "highestQuality" and the a cfimage "write"
instead of just doing a cfimage "resize" for some reason. Also I found
that setting the quality attribute on the cfimage "write" to 0.9 gave
the best quality -v- filesize.

Kind regards,

Andrew.

On Jul 19, 7:27 pm, Completely Free Dating - Andrew

Dave

unread,
Jul 20, 2009, 4:54:56 AM7/20/09
to ra...@googlegroups.com
My images seem to come out good so I wouldn't say it's railo.
Whats your java ram set to? If it is too low it might be just
squeezing it through.

Dave

unread,
Jul 20, 2009, 4:56:37 AM7/20/09
to ra...@googlegroups.com
I would try a png

did you add what the error says is missing
"at javax.imageio.ImageWriteParam.setCompressionQuality(Unknown
> Source):-1"

Dave

unread,
Jul 20, 2009, 4:58:45 AM7/20/09
to ra...@googlegroups.com
I do that as well with no issues.
Is your java up to date? I seem to recall an issue with java and this
awhile back.

Completely Free Dating - Andrew

unread,
Jul 20, 2009, 1:51:24 PM7/20/09
to Railo
Hi Dave,

Like I said, it was image DPI causing the problem. My memory is set to
256mb and java is up-to-date and the original image was 168kb so I
don't think it would be anything like that. Also there is no
Compression quality setting for a BMP (bitmap) file as it is a bitmap
and has no compression, so that is a bug in Railo.

Kind regards,

Andrew.

Dave

unread,
Jul 20, 2009, 2:52:51 PM7/20/09
to ra...@googlegroups.com
ok so you are saying that it is railo's fault that a bmp can't be
compressed? If thats the case then what does railo have to do with
that? If I recall correctly bmp is a m$ file.
If that's the issue then save it as a png or tiff like was said before.

ok next... so you have a 300dpi photo larger than 250 px and it is
only 168kb?
There is something wrong with that. How is the dpi the issue? I can
take a very high res photo right of my nikon d200 and run it through
just fine. And I can take one of those images and scale it down to
250px and it is still 2x the size of your image.

256mb isn't very much ram for it, when I first installed railo it
would crap out resizing images on the default 81mb and those were
small photos and no other sites running at the time.

Feel free to send me one of your image to try on my server and to
check image info, most photos shouldn't be over 240dpi with pro cameras.

Michael Hnat - bluegras

unread,
Jul 20, 2009, 3:11:40 PM7/20/09
to ra...@googlegroups.com
Just want to add my 2 cents.
Is it a clean jpg file?
Or is it an interlaced image or a psd saved as jpg (with all layers, etc.)?

Cheers,
Michi

-----Ursprüngliche Nachricht-----
Von: ra...@googlegroups.com [mailto:ra...@googlegroups.com] Im Auftrag von
Dave
Gesendet: Montag, 20. Juli 2009 20:53
An: ra...@googlegroups.com
Betreff: [railo] Re: Image Resize Quality

Peter Boughton

unread,
Jul 20, 2009, 3:24:34 PM7/20/09
to ra...@googlegroups.com
> ok next... so you have a 300dpi photo larger than 250 px and it is
> only 168kb?

DPI has *absolutely nothing* to do with filesize.

Infact, the DPI value in an image file doesn't actually affect the
image at all, and can be modified (with an appropriate editor) without
changing the image in any way.

Peter Boughton

unread,
Jul 20, 2009, 3:42:08 PM7/20/09
to ra...@googlegroups.com
Hi Andrew,

Just re-reading this thread and trying to figure it out... can you
recap on what you're trying to achieve and what's going wrong?

(i.e. Am I right in thinking this BMP stuff is just a rabbit hole
caused by attempting to find a workaround to a problem with resizing a
JPG?)


Thanks,

Peter

Dave

unread,
Jul 20, 2009, 3:53:59 PM7/20/09
to ra...@googlegroups.com
Well technically it doesn't especially if it has a human operator
that can take it down then resize it back up but as far as I know
these auto image resizers don't do that. Since you only need 72dpi for
a computer screen you can't see the difference but you have a smaller
file size by doing down. Although using either seems to work fine. I
have yet to see a good sized file in 300dpi and be that small of a
file & any time I have seen something remotely close to that is when a
client shunk the photo and then tried to enlarge it back at a later
date which just made the file bigger, the quality worse and corrupted
the data in it.

these are straight off camera and you can see the change and
difference but you "could" reduce dpi the enlarge image.
http://www.quicksnapper.com/jamwerx/image/240
http://www.quicksnapper.com/jamwerx/image/72

Completely Free Dating - Andrew

unread,
Jul 20, 2009, 4:16:00 PM7/20/09
to Railo
Ok, let me address both Peter and Dave, starting with Peter.

Peter,

Right this is quiet similar but I think Dave has complicated it all.

1) I have an image that is 412px wide and 300DPI (I didn't notice it
was 300DPI to start with).

2) I wrote code to resize it to 250px wide and the the output image
was quality was appauling.

3) I posted on the group here and someone suggested a work around
based on blog post on Coldfusion Jedi site.

4) The work around was to convert the image to read the image into CF
and then write it back to disk as a BMP (something which Railo error
on when you attempt it, so reply to Dave below).

5) I then noticed the file was 300 DPI and if I open the file using
cfimage and then save it using cfimage without doing any manipulation
Railo resampled it from 300 DPI to 72 DPI. I then resize this new 72
DPI version using Railo and it worked fine and the quality was good.

I would still maintance that this poor handling is a "bug" as such,
but you can work around it as describe which mean for me the problem
is solved.

Dave,

A BMP has no compression as the BMP format is not a compressed format.
This is not a Railo issue it is just a fact (see
http://en.wikipedia.org/wiki/BMP_file_format). The issue is that the
code in Railo when writing an image seem to want a value for the
setCompressionQuality even through the format it is trying to write in
doesn't have a value for that particular file type. This is the Railo
bug.

Kind regards,

Andrew.

On Jul 20, 8:53 pm, Dave <cfl...@jamwerx.com> wrote:
> Well technically it doesn't  especially if it has a human operator  
> that can take it down then resize it back up but as far as I know  
> these auto image resizers don't do that. Since you only need 72dpi for  
> a computer screen you can't see the difference  but you have a smaller  
> file size by doing down. Although using either seems to work fine. I  
> have yet to see a good sized file in 300dpi and be that small of a  
> file & any time I have seen something remotely close to that is when a  
> client shunk the photo and then tried to enlarge it back at a later  
> date which just made the file bigger, the quality worse and corrupted  
> the data in it.
>
> these are straight off camera and you can see the change and  
> difference but you "could" reduce dpi the enlarge image.http://www.quicksnapper.com/jamwerx/image/240http://www.quicksnapper.com/jamwerx/image/72

Peter Boughton

unread,
Jul 20, 2009, 4:28:03 PM7/20/09
to ra...@googlegroups.com
Let me repeat: DPI has *absolutely nothing* to do with filesize.

Really. Look at this: http://bpsite.net/misc/dpi_filesize.png - the
filesizes are *identical* because the image has not been changed for
either of them!

Don't confuse resizing the dimensions of an image with changing its
DPI / PPI values.

Unfortunately, the resize dialog in Photoshop causes confusion in this
- because it locks the physical (print) size of an image, it means
that modifying the pixels/inch value will also alter the image pixel
dimensions (and visa versa) - but it is important to know that it is
the changing of pixel width/height values (from 2592x3872 to 778x1162)
which modifies the filesize of the image (because there are less
pixels to store data about, and thus lower quality).
The change to the DPI is just a side-effect due to Photoshop locking
the physical size.

Dave

unread,
Jul 20, 2009, 4:35:07 PM7/20/09
to ra...@googlegroups.com
it's ok none of use understand what the other is saying and I been up
way to long to figure it out.

Peter Boughton

unread,
Jul 20, 2009, 4:42:49 PM7/20/09
to ra...@googlegroups.com
Ah, ok I'm following things now. :)

First thing to re-iterate (if I haven't gone on about it enough) is
that DPI has nothing to do with quality of a digital image. It only
has relevance at the printing stage (when the image is converted to
physical dots on a page).

So, whilst it shouldn't be the culprit for the bad image quality, it
is a little odd that cfimage is changing the dpi to 72 - and perhaps
odder that in all my tests it is changing the dpi to 96 (even with an
image originally set to 72).

However, I've experimented with an assortment of jpg and png images,
with the read/resize/write code from your original post (variables and
formatting changed, but same functionality), and I'm not getting any
quality issues.

So, I guess first thing to check is what Railo versions we have, in
case there is some change to versions of the image libraries used
between these versions.

For these tests it looks like I'm running against Railo 3.1.0.012
(should really download the updates) on Java 1.6.0_11 and Win XP sp2.

Also, can the original image you were trying to resize be made public?
(in case there is some odd issue with the image itself, as Michael suggested)

Dave

unread,
Jul 20, 2009, 4:49:42 PM7/20/09
to ra...@googlegroups.com
you dont need to re-iterate it, what I was saying is that I didn't
know if when the image is resized if it was such a large dpi if it was
reducing it then trying to enlarge it back to size. Like when a client
gives you a pic "right off their camera" that is 48kb and is
1000x1000.. they shruck it then tried to make it bigger... that's what
I was suggesting.


@andrew
yes i see your point now, before to me you were saying railo was in
the wrong because a bmp can't be compressed. I would still go with a
png anyways... bmp is crap

Peter Boughton

unread,
Jul 20, 2009, 5:00:40 PM7/20/09
to ra...@googlegroups.com
> The issue is that the
> code in Railo when writing an image seem to want a value for the
> setCompressionQuality even through the format it is trying to write in
> doesn't have a value for that particular file type. This is the Railo
> bug.

Yep, this is definitely a bug - here is some simple code to reproduce
the problem:


<cfset InputImage = "./images/random_bitmap.bmp" />
<cfset OutputImage = "./images/new_image.bmp" />

<cfimage
source = "#InputImage#"
name = "MyBitmap"
/>

<cfimage
action = "write"
source = "#MyBitmap#"
destination = "#OutputImage#"
/>

This throws the error "No compression type set!" and creates a
zero-byte new_image.bmp file.

The quality attribute should be optional for any uncompressed format

(I'd probably even suggest it should be optional (default to 1) for
compressed formats too.)


If someone wants to create a Jira issue for this specific issue that'd
be great - if not I'll do it after I've had some dinner. :)

Completely Free Dating - Andrew

unread,
Jul 20, 2009, 6:13:23 PM7/20/09
to Railo
Hi Peter,

I'm note sure how to raise a bug so I will leave that with you.

Also I will send you a copy of the image I'm having trouble with
directly to your gmail account so you can take a look at it and
hopefully be able to reproduce the resize quality issue.

Kind regards,

Andrew.

Peter Boughton

unread,
Jul 20, 2009, 6:44:59 PM7/20/09
to ra...@googlegroups.com
Ok, issue created https://jira.jboss.org/jira/browse/RAILO-320

I'm testing with the image you sent, but so far I don't get the issue
with a straight cfimage/resize - the quality of the output image has
no problems.

Michael Offner-Streit

unread,
Jul 21, 2009, 2:37:43 AM7/21/09
to ra...@googlegroups.com
can you please make a ticket for this here
https://jira.jboss.org/jira/browse/RAILO

and attach some example code with images

tnx a lot micha



Completely Free Dating - Andrew schrieb:
--
Michael Offner-Streit
CTO
Railo Technologies GmbH
michael...@railo.ch
www.getrailo.com

Mailing List (english): http://groups.yahoo.com/group/railo_talk/
Mailing List (german): http://de.groups.yahoo.com/group/railo/
Linked in: http://www.linkedin.com/e/gis/71368/0CF7D323BBC1
Issue Tracker: http://jira.jboss.org/jira/browse/RAILO
Blog: http://www.railo-technologies.com/blog


Michael Offner-Streit

unread,
Jul 21, 2009, 2:52:54 AM7/21/09
to ra...@googlegroups.com
sorry mail was already in pipline before i have seen that there is already a ticket

/micha

Michael Offner-Streit schrieb:
Reply all
Reply to author
Forward
0 new messages