![]() |
| Image resize. |
|
Ennio
|
What is the best way to resize an image and not have the image all streched.
I'm trying to resize some images that the user upload to be 120x150 but the image look funny after resize it. I'm using CF8 and cfimage to do that. |
||||||||||||
|
|
|||||||||||||
|
Jason101
Forum Regular
|
Ennio,
Use CFImage with ImageScaleToFit() to resize the image proportionally Heres an example:
The above will resize the image proportionally to a max of 150px high. If you wish to resize based on width, just set 120 as the second argument, and set the third argument to ''. Here are the quickdocs: http://www.cfquickdocs.com/cf8/#ImageScaleToFit |
||||||||||||||
|
|
|||||||||||||||
|
emmet
|
|||||||||||||
|
|
|||||||||||||
|
Jason101
Forum Regular
|
This will do FixedAscpect. Why use thrid party utilities when CF8 image functions far exceed any of them. (This wasn't true with Pre CF8) |
||||||||||||||
|
|
|||||||||||||||
|
emmet
|
I think your misunderstanding. Scaletofit maintains aspect but does not apply a fixed size. He specifically said 120x150. Scaletofit will only insure its not greater than 120 wide or 150 tall.
Also, you didn't take a look at imageUtils i take it. They are mash up utils that only use cf8's built in image functionality and some math. |
||||||||||||
|
|
|||||||||||||
|
Jason101
Forum Regular
|
Emmet, I did misunderstand. I will take a look at image Utils. Thanks for clarifying |
||||||||||||||
|
|
|||||||||||||||
|
Ennio
|
Hi guys...
Sorry I've been busy and had much time to work on the image... But I was looking for something to make the image on the fix ration 150x120 I will take a look tomorrow on that. |
||||||||||||
|
|
|||||||||||||
|
Ennio
|
Emmet,
Thanks for the link that worked great. |
||||||||||||
|
|
|||||||||||||
|
emmet
|
Glad it worked out.
|
||||||||||||
|
|
|||||||||||||
|
Ennio
|
It's very simple to use nice job.
One question, today I was doing some more testing and I tried to upload a file from my digital camera, a JPGE image, and I keep on getting this error msg. And I tried another image and it worked. An exception occured while trying to write the image. Ensure that the destination directory exists and that Coldfusion has permission to write to the given path or file. cause : java.io.FileNotFoundException: C:\Websites\em47126e\babyimg\Autumn Leaves.jpg (The system cannot find the file specified) When I look at the website the image is beeing uploaded. Any reason why that would happened? Here is my code. My Form
And here is my upload code.
|
||||||||||||||||
|
|
|||||||||||||||||
|
Ennio
|
I think the error is around this code
Because when I remove this part the image uploads ok to the server. |
||||||||||||||
|
|
|||||||||||||||
|
emmet
|
The only explanation is that cf isn't seeing your digital camera image as an image. The function fails gracefully and will throw an error. To see the error you need to use cfcatch around your write. Something like
<cftry> <--- your code ---> <cfcatch> <p>#cfcatch.message#</p> </cfcatch> </cftry> If it errors it will give you a "The value passed to aspectCrop was not an image." Your other quick option is just testing the image with isImageFile(yourimage) and seeing what it returns. I'm curious though, is your image extension .jpge or was that a typo? |
||||||||||||
|
|
|||||||||||||
|
Ennio
|
Sorry it was a typo it's jpg.
I get this error msg. An exception occured while trying to write the image. |
||||||||||||
|
|
|||||||||||||
|
emmet
|
Thats your general exception or your cfcatch.message? Did you tet the image with isimagefile()?
|
||||||||||||
|
|
|||||||||||||
|
Ennio
|
I used the cfcatch.message
|
||||||||||||
|
|
|||||||||||||
| Image resize. |
|
||
|


