Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to resize with CFImage and actually reducing the image file size? [duplicate]

Possible Duplicate:
Why should I resize an image in Coldfusion if the file size doen't decrease and the quality of the image suffers?

I must be doing something wrong here... using Coldfuison8

I have a product search which is pulling in images from external servers, so I need to set images on runtime.

Say I have a jpg 500x500px 111kb, which I'm grabbing from the external server.

Right now I'm doing this:

<cfimage name="myImage" source="#bildpfad##bilddateiname#" action="read" />
<cfif IsImage(myImage) is true>
    <cfscript>
    ImageSetAntialiasing(myImage,"on");
    variables.breite = 400;
        ImageScaleToFit(myImage, variables.breite,"", "highestPerformance");
    </cfscript>
<cfxml variable="imageXml">
    <cfimage action="writetobrowser" source="#myImage#" />
</cfxml>
<cfoutput><div class="resultsImgWrap">#imageXml#</div></cfoutput>

This displays the image allright, but when I check the filesize, I have

400x400px 111.2kB

If I use IrfanView for example and just reduce the filesize and save the image, I'm already at 65kb.

Question: How can I make CFIMAGE reduce the file size if I'm resizing the image? If the size stays at 111kb, why use CFIMAGE at all and not simply add the image as plain HTML.

**EDIT'':
The variables Bildpfad and Bilddateiname will be something like:

bildpfad (path to image):         http://www.some-server.com/images/
bilddateiname (filename):         some_image123.jpg
like image 293
frequent Avatar asked Dec 31 '25 19:12

frequent


2 Answers

Specify the quality attribute in <cfimage>. I'm not sure if it works with action="writeToBrowser", but it should. Otherwise, file a bug report.

Resize and Compression are different things. :)

See: Why should I resize an image in Coldfusion if the file size doen't decrease and the quality of the image suffers?

UPDATE

Good news, there's an undocumented way to get it working! See: http://www.bennadel.com/blog/2405-Using-The-Quality-Attribute-With-The-CFImage-WriteToBrowser-Action.htm

<!--- Write out as a JPG at 20% (using "quality" attribute). --->
<cfimage
    action="writeToBrowser"
    source="#png#"
    format="jpg"
    quality=".2"
    />
like image 105
Henry Avatar answered Jan 05 '26 05:01

Henry


Resizing an image it not intended to make the file size smaller in bytes. It is to make it smaller by height and width. Yes, more often than not the image file size does become smaller. But that size reduction depends on the source image.

You might want to declare the format as png as that may help make the file smaller.

Also, why are you wrapping the cfimage tag in cfxml? That is a useless step that is causing extra processing and bloat.

like image 22
Dave Ferguson Avatar answered Jan 05 '26 07:01

Dave Ferguson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!