> Does anyone have a snippet of code to determine the size of an image (any
> format; gif,jpg,png...) ?
Have you try CFX_Image?[1] (Need to register on the site before downloading).
--
[2048/1024 bit DH/DSS <ll...@u.washington.edu>]
Key ID: 0xF1B44F9D
http://students.washington.edu/llin/
> On Wed, 2 Oct 2002, absyrtus wrote:
>
>> Does anyone have a snippet of code to determine the size of an image
>> (any format; gif,jpg,png...) ?
>
> Have you try CFX_Image?[1] (Need to register on the site before
> downloading).
>
> [1]: http://www.gafware.com/
>
Yes I have, but I'm not very keen on using a custom tag anymore. There
should be a scripting way of determining the sizes (as there is one for
Vbscript (ASP) which I've seen somewhere)
Anyone?
T.I.A.
Ab
The VScript solution almost assuredly uses a COM object to do the real
work - an object that you should be able to use within CF as well. If you
find the ASP example you mentioned it should be pretty easy to convert it to
CF.
Jim Davis
>> Yes I have, but I'm not very keen on using a custom tag anymore.
>> There should be a scripting way of determining the sizes (as there is
>> one for Vbscript (ASP) which I've seen somewhere)
>> Anyone?
>
> The VScript solution almost assuredly uses a COM object to do the real
> work - an object that you should be able to use within CF as well. If
> you find the ASP example you mentioned it should be pretty easy to
> convert it to CF.
Jim,
It took me some time, but I've found the script I meant at:
http://www.4guysfromrolla.com/webtech/code/imgsz.asp.html
I like to give it a try to convert, but I wonder already if there are
equivalents to binary reading a couple of bytes from f.e. a jpg file.
Ab
Continue:
I've put together the following.
It should display GIF89 with ASCII values 71 73 70 56 57
I'm Getting: R(82) 0(48) l(108) G(71) O(79)
<html>
<body>
<cfset MyPath = "C:\">
<cfset MyFile = "test3.gif">
<cffile action="READBINARY" file="#MyPath##MyFile#" variable="TT">
<cfset TTT = ToBase64(#TT#)>
<cfloop index="x" from="1" to="5" step="1">
<cfset #a1# = #mid(TTT,x,1)#>
<cfset #a2# = #asc(mid(TTT,x,1))#>
<cfoutput>#a1#(#a2#) </cfoutput>
</cfloop>
</body>
</html>
Any clues where I'm doing wrong?
The function IsBinary("TT") returns NO. Which I also don't understand..
Ab
To Answer my own question:
<HTML>
<BODY>
<cfset MyPath = "C:\">
<cfset MyFile = "test4.gif">
<cffile action="READ" file="#MyPath##MyFile#" variable="FileBytes">
<cfset FirstThree = "">
<cfloop index="x" from="1" to="3" step="1">
<cfset FirstThree = #FirstThree# & #mid(FileBytes,x,1)#>
</cfloop>
<CFSET width=0>
<CFSET height=0>
<CFSET color=0>
<cfif #FirstThree# EQ "GIF">
<cfset #width# = (#asc(mid(FileBytes,8,1))#*256)+#asc(mid
(FileBytes,7,1))#>
<cfset #height# = (#asc(mid(FileBytes,10,1))#*256)+#asc(mid
(FileBytes,9,1))#>
<cfset #color# = 2^(bitand(#asc(mid(FileBytes,11,1))#,7)+1)>
</cfif>
*<cfoutput>#width# #height# #color#</cfoutput>*
</body>
</html>
This is fun! Now for the other formats ;-)
Ab
Okay, Here's the one for bmp,jpg,gif and png:
(notice the possible wordwrapping).
Sorry for thinking out loud in this group.
CF is Fun!
Ab
<HTML>
<BODY>
<cfset MyPath = "C:\">
<cfset MyFile = "test.jpg">
<CFSET width=0>
<CFSET height=0>
<CFSET color=0>
<cffile action="READ" file="#MyPath##MyFile#" variable="FileBytes">
<cfset FirstThree = "">
<cfloop index="x" from="1" to="3" step="1">
<cfset FirstThree = #FirstThree# & #mid(FileBytes,x,1)#>
</cfloop>
<cfif #FirstThree# EQ "GIF"> <!--- gif --->
<cfset #width# = (#asc(mid(FileBytes,8,1))#*256)+#asc(mid
(FileBytes,7,1))#>
<cfset #height# = (#asc(mid(FileBytes,10,1))#*256)+#asc(mid
(FileBytes,9,1))#>
<cfset #color# = 2^(bitand(#asc(mid(FileBytes,11,1))#,7)+1)>
<cfelseif mid(#FirstThree#,1,2) EQ "BM"> <!--- bmp --->
<cfset #width# = (#asc(mid(FileBytes,20,1))#*256)+#asc(mid
(FileBytes,19,1))#>
<cfset #height# = (#asc(mid(FileBytes,24,1))#*256)+#asc(mid
(FileBytes,23,1))#>
<cfset #color# = 2^(#asc(mid(FileBytes,29,1))#)>
<cfelseif #FirstThree# EQ "臼N"> <!--- png --->
<cfset #width# = (#asc(mid(FileBytes,19,1))#*256)+#asc(mid
(FileBytes,20,1))#>
<cfset #height# = (#asc(mid(FileBytes,23,1))#*256)+#asc(mid
(FileBytes,24,1))#>
<cfset #tmpcolorpower# = (#asc(mid(FileBytes,25,1))#)>
<cfset #tmpcolortype# = (#asc(mid(FileBytes,26,1))#)>
<cfif #tmpcolortype# EQ 0>
<cfset #color# = 2^(#tmpcolorpower#)>
<cfelseif #tmpcolortype# EQ 2>
<cfset #color# = 2^((#tmpcolorpower#)*3)>
<cfelseif #tmpcolortype# EQ 3>
<cfset #color# = 2^(#tmpcolorpower#)>
<cfelseif #tmpcolortype# EQ 4>
<cfset #color# = 2^((#tmpcolorpower#)*2)>
<cfelseif #tmpcolortype# EQ 6>
<cfset #color# = 2^((#tmpcolorpower#)*4)>
<cfelse>
<cfset #color# = -1>
</cfif>
<cfelse>
<cfset #FileBytesSize# = Len(FileBytes)>
<cfset #FlagFound# = 0>
<cfset #FlagFound# = Find(chr(255) & chr(216) & chr(255),
#FileBytes#)>
<cfif #FlagFound# GT 0 >
<cfset #Position# = #Flagfound# + 2>
<cfset #ExitLoop# = FALSE>
<CFLOOP CONDITION = "((#Exitloop# EQ FALSE) AND (#Position# LT
#FileBytesSize#))">
<CFLOOP CONDITION = "(asc(mid(#FileBytes#,#Position#,1)) EQ
255) AND (#Position# LT #FileBytesSize#)">
<CFSET #Position# = #Position# + 1>
</CFLOOP>
<CFIF ((#asc(mid(FileBytes,Position,1))# LT 192) OR (#asc(mid
(FileBytes,Position,1))# GT 195))>
<cfset #MarkerSize# = (#asc(mid(FileBytes,Position+1,1))
#*256)+#asc(mid(FileBytes,Position+2,1))#>
<cfset #Position# = #Position#+#MarkerSize#+1>
<CFELSE>
<cfset ExitLoop = TRUE>
</CFIF>
</CFLOOP>
<CFIF #Exitloop# EQ FALSE>
<cfset #width# = -1>
<cfset #height# = -1>
<cfset #color# = -1>
<CFELSE> <!--- jpg --->
<cfset #height# = (#asc(mid(FileBytes,Position+4,1))#*256)
+#asc(mid(FileBytes,Position+5,1))#>
<cfset #width# = (#asc(mid(FileBytes,Position+6,1))#*256)+#asc
(mid(FileBytes,Position+7,1))#>
<cfset #color# = 2^(#asc(mid(FileBytes,Position+8,1))#*8)>
</CFIF>
<cfelse>
No GIF,BMP,PNG or JPG !!<BR><BR>
</cfif>
</cfif>
<cfoutput>
Width =#width#<BR>
Height=#height#<BR>
Color =#color#<BR>
</cfoutput>
</body>
</html>
I would have probably tried to use the FileSystem object that the ASP used
(CFOBJECT) but using a completely CF solution is just so much cooler...
Jm Davis
"absyrtus" <absy...@hotmail.com> wrote in message
news:Xns929CD1A42690Fa...@212.83.64.210...
> <cfelseif #FirstThree# EQ "?PN"> <!--- png --->