This is my own version of imagesize.cfm, optimized and changed slightly.
I do not use this tag anymore and will be writing a DLL version.
The use of a DLL version is highly recommended, but here you go anyway...

You might want to cache the results it determines if you use this in a production 
environment.
(In a database of some sort most likely)

Please visit http://efflare.com/?hf for other related custom tags.

<!---
JPEG is slow, GIF is fast

attributes.file -> full path

returns :
Image.Width:  The width of the image
Image.Height: The height of the image
Image.Type:   returns the Precision if JPG, and Gif Type if GIF
--->
<cfsilent>

<cffile action="READ" file="#Attributes.file#" variable="Gif">

<cfscript>
caller.image.error=1;
caller.image.height=0;
caller.image.width=0;
caller.image.type=0;
Type_JPG="����";
Type_GIF="GIF8";
Image.Width="";
Image.Height="";
ImageType=Left(GIF,4);
</cfscript>

<CFIF ImageType is Type_JPG>

 <cfset header="">
 <CFSET p = 1>
 <CFLOOP Condition="p LE Len(GIF)">
  <CFSET currentByte=Mid(Gif,p,1)>
  <CFIF  (ASC(currentByte) is 218) >
    <CFBREAK>
  </CFIF>
  <CFSET Header=ListAppend(Header,ASC(currentByte))>
  <CFSET p = p +1>
 </cfloop>

 <cfscript>
 p=0;
 if (p is 0) {
 p = Find("255,192",Header);
 }
 if (p is 0) {
 p = Find("255,193",Header);
 }
 if (p is 0) {
 p = Find("255,194",Header);
 }
 if (p is 0) {
 p = Find("255,195",Header);
 }
 // These are probably not used after these first four...
 if (p is 0) {
 p = Find("255,196",Header);
 }
 if (p is 0) {
 p = Find("255,197",Header);
 }
 if (p is 0) {
 p = Find("255,198",Header);
 }
 if (p is 0) {
 p = Find("255,199",Header);
 }
 if (p is 0) {
 p = Find("255,201",Header);
 }
 if (p is 0) {
 p = Find("255,202",Header);
 }
 if (p is 0) {
 p = Find("255,203",Header);
 }
 if (p is 0) {
 p = Find("255,205",Header);
 }
 if (p is 0) {
 p = Find("255,206",Header);
 }
 if (p is 0) {
 p = Find("255,207",Header);
 }

 if (p is 0) {
 writeoutput("<!-- image error A -->");
 } else {
 Header=Mid(Header,p,Len(Header) - p);
 CompressionType=ListGetAt(Header,2);
 Length=ListGetAt(Header,3) & " " & ListGetAt(Header,4);
 Caller.Image.Type=ListGetAt(Header,5);
 Caller.Image.Height=(ListGetAt(Header,6)*256) + ListGetAt(Header,7);
 Caller.Image.Width=(ListGetAt(Header,8)*256) + ListGetAt(Header,9);
 caller.image.error = 0;
 }
 </cfscript>

<CFELSEIF ImageType is Type_GIF>

 <cfscript>
 Caller.Image.Width=(ASC(Mid(Gif, 7, 1)) + (ASC(Mid(Gif, 8, 1)))*256);
 Caller.Image.Height=(ASC(Mid(Gif, 9, 1)) + (ASC(Mid(Gif, 10, 1)))*256);
 Caller.Image.Type=Mid(Gif, 1, 6);
 caller.image.error = 0;
 </cfscript>

<CFELSE>

 <!-- image error B -->

</cfif>

</cfsilent>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Efflare Systems :: http://efflare.com :: [EMAIL PROTECTED]
 cfx ImageCR :: http://efflare.com/products/cfx_imagecr/?sig
 cfx gFont :: http://efflare.com/products/cfx_gfont/?sig

----- Original Message -----
From: "Shawn Grover" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Monday, December 10, 2001 10:21 AM
Subject: RE: Custom Tag to resize JPG on the fly...


> The other problem with this is that you need to know the original
> dimensions
> of the image programatically to determine your aspect ratio.  To do
> this
> manually for one or two images is fine, but when you have a folder with
> thousands of images that are displayed dynamically, then this becomes
> extremely time consuming and inefficient.
>
> Is there some way to determine the original dimensions programatically?
> I've yet to come across anything that is useful to me - CFX_Image is
> not an
> option because I do not control the server in question and cannot
> install
> DLLs.  Perhaps there's something simpler I've missed?
>
> Shawn Grover
>
> -----Original Message-----
> From: Garza, Jeff [mailto:[EMAIL PROTECTED]]
> Sent: Friday, December 07, 2001 4:04 PM
> To: CF-Talk
> Subject: RE: Custom Tag to resize JPG on the fly...
>
>
> The only problem with this is you are still downloading the entire
> image
> rather than the smaller thumbnail or whatever.  I think the purpose is
> to
> reduce the physical size/resolution for a smaller download.
>
> I've been fiddling with the Perl Image Magick modules for this.
> Running the
> commands from cfexecute.  It's slow since I don't know Perl all that
> well....
>
> Jeff Garza
> Lead Developer/Webmaster
> Spectrum Astro, Inc.
> 480.892.8200
> [EMAIL PROTECTED]
> http://www.spectrumastro.com
>
>
>
> -----Original Message-----
> From: Mookie Bear [mailto:[EMAIL PROTECTED]]
> Sent: Friday, December 07, 2001 4:00 PM
> To: CF-Talk
> Subject: RE: Custom Tag to resize JPG on the fly...
>
>
> or, you can use proportions to resize the pic :)
>
> for example, i have a pic that is 237 in width and 500 height.
>
> lets say i want to shrink it down to a width of 150.  to get the
> proportionate height (i knew this would come in handy one day since 4th
>
>
> grade!) just solve this equation  (237/500) = (150/x)
>
> blah, u should remember this stuff, right? :)
>
>
>
>
>
>
>
> >From: "Joseph DeVore" <[EMAIL PROTECTED]>
> >Reply-To: [EMAIL PROTECTED]
> >To: CF-Talk <[EMAIL PROTECTED]>
> >Subject: RE: Custom Tag to resize JPG on the fly...
> >Date: Fri, 7 Dec 2001 14:26:23 -0800
> >
> >CFX_IMAGE by Jukka Manner can do this for you.
> >
> >You can download it from Lewis Sellers website at
> >http://intrafoundation.com/3rdparty/CFX_Image.zip
> >
> >
> >Joseph DeVore
> >VeloxWeb Technologies
> >
> >
> >
> >-----Original Message-----
> >From: Jared Stark [mailto:[EMAIL PROTECTED]]
> >Sent: Friday, December 07, 2001 2:10 PM
> >To: CF-Talk
> >Subject: Custom Tag to resize JPG on the fly...
> >
> >
> >I have been looking on the Allaire website for a tag to thumbnail JPG
> >images on the fly.  I've found one that does GIF, but I need JPG.
> >Anyone know of a good one that they can recommend?  I must admit that
> >I'm taca�o(AKA cheap), and I'm looking for a free one.
> >
> >Thanks,
> >Jared
> >
> >
> >
>
>
> 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to