• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Possible to determine image dimensions on cffile upload?

New Here ,
Mar 23, 2007 Mar 23, 2007

Copy link to clipboard

Copied

Hello,

Is there any way to determine the pixel dimensions of a jpg or gif image file that has been uploaded using cffile?

Regards,
Greg
TOPICS
Advanced techniques

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Mar 24, 2007 Mar 24, 2007
or...

<cfset image_name ="C:\pathtofile\imagefile.jpg">

<cfscript>
imgFile = createObject("java","javax.swing.ImageIcon").init("#image_name#");
imgFile.getImage();
w = imgFile.getIconWidth();
h = imgFile.getIconHeight();
</cfscript>

<cfoutput>width="#w#" height="#h#</cfoutput>


Adjust code accordingly to what you are doing.

Votes

Translate

Translate
Guest
Mar 23, 2007 Mar 23, 2007

Copy link to clipboard

Copied

Page 6 of http://www.w3.org/Graphics/JPEG/jfif3.pdf describes the location of the Xdensity and Ydensity fields (2 bytes each) for a JPEG. http://www.martinreddy.net/gfx/2d/GIF87a.txt will tell you similar information about the GIF file format.

If that's too much to digest, get yourself a good custom tag, or wait for native functionality in ColdFusion 8. Google coldFusion "custom tag" "image size"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 23, 2007 Mar 23, 2007

Copy link to clipboard

Copied

Yes, I use a script that will determine the dimensions so I can put the heigth and width into database fields for use laster. I will attach the code I use for you.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 24, 2007 Mar 24, 2007

Copy link to clipboard

Copied

or...

<cfset image_name ="C:\pathtofile\imagefile.jpg">

<cfscript>
imgFile = createObject("java","javax.swing.ImageIcon").init("#image_name#");
imgFile.getImage();
w = imgFile.getIconWidth();
h = imgFile.getIconHeight();
</cfscript>

<cfoutput>width="#w#" height="#h#</cfoutput>


Adjust code accordingly to what you are doing.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 26, 2007 Mar 26, 2007

Copy link to clipboard

Copied

Abinidi wrote:

> <cfscript>
> imgFile = createObject("java","javax.swing.ImageIcon").init("#image_name#");
> imgFile.getImage();
> w = imgFile.getIconWidth();
> h = imgFile.getIconHeight();
> </cfscript>

this is way cool, man!
do you know if there is a way to check the dimensions of an uploaded
flash (swf) movie ?

--
Azadi Saryev
Sabai-dee.com
Vientiane, Laos
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 26, 2007 Mar 26, 2007

Copy link to clipboard

Copied

>do you know if there is a way to check the dimensions of an uploaded
>flash (swf) movie ?

I have never used it but you might check out FlashInspector.CFC at
http://www.doughughes.net/index.cfm?event=viewEntry&entryId=166

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 26, 2007 Mar 26, 2007

Copy link to clipboard

Copied

exactly what i needed! thanks a bunch!

--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 01, 2007 Apr 01, 2007

Copy link to clipboard

Copied

Abinidi wrote:
> or...
>
> <cfset image_name ="C:\pathtofile\imagefile.jpg">
>
> <cfscript>
> imgFile = createObject("java","javax.swing.ImageIcon").init("#image_name#");
> imgFile.getImage();
> w = imgFile.getIconWidth();
> h = imgFile.getIconHeight();
> </cfscript>
>
> <cfoutput>width="#w#" height="#h#</cfoutput>
>
>
> Adjust code accordingly to what you are doing.
>

i am trying to use the above code to check for dimensions of uploaded
image and delete the image (through cffile action=delete) if its
dimensions are different from required. the checking part works fine,
but i am unable to delete the image!
CF trows an error:
ColdFusion could not delete the file "[full path to file]\[filename]"
for an unknown reason.

the path is correct, the file is there, and i can delete it manually
without a problem, but not with cffile action=delete...

any ideas? does that have something to do with the instantiated java
object? how do i de-instantiate it?

--
Azadi Saryev
Sabai-dee.com
Vientiane, Laos
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2007 Apr 02, 2007

Copy link to clipboard

Copied

well, i have come up with a work-around, but would still like to learn
how (if possible) to release a java object invoked with createObject()...

in case anyone is interested, the work-around i implemented is:
add uploaded files of wrong dimensions to a list, after succefful upload
of correct file pass the list to another page which silently loops
through it and deletes the files from server and returns user to
original calling page...
--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 27, 2007 Apr 27, 2007

Copy link to clipboard

Copied

Azadi,

I ran a few tests and cffile delete worked. So I'm not sure what the problem is. I looked at the cfc and it refers to two java classes.

java.io.ByteArrayInputStream
java.util.zip.InflaterInputStream

Both classes have a close() method, though ByteArrayInputStream.close() doesn't do anything. For grins .. you might try adding a function to the FlashInspector.cfc that calls the close() method on the java objects. Then call that function just before attempting to deleting the file. I don't know that it will help but its worth a shot.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 27, 2007 Apr 27, 2007

Copy link to clipboard

Copied

thanks for your input, cf_dev2!

i was actually having the problem with getting jpeg dimensions using
Abinidi's code that uses javax.swing.ImageIcon class, not the
FlashInspector.cfc...

the FlashInspector works like a charm... it's the created java object
that would not release and let me delete the jpeg image if its
dimensions are wrong...

i have since switched to using imagecfc from opensourcecf - a lot more
code, but all packed into a cfc, and lets you resize/crop the image to
correct dimensions instead of just telling the user "sorry, your image
is wrong size, please resize and re-upload"...

but thank for your time looking into this, and your url for the
FlashInspector.cfc was a true lifesaver!

--
Azadi Saryev
Sabai-dee.com
Vientiane, Laos
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 28, 2007 Apr 28, 2007

Copy link to clipboard

Copied

LATEST
> i was actually having the problem with getting jpeg dimensions

Azadi,

Well that's what I get for trying to read before I've had my morning coffee ;-)

Now that I think about it I remember having a similar problem. Either with java.swing.ImageIcon or java.awt.Image or both. But it sounds like imagecfc has solved your problem and it does have some great features.

Until next time then!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation