Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image width en height + SQL server storage

Status
Not open for further replies.

Bramvg

IS-IT--Management
Jan 16, 2001
135
BE
Hello,

Is theire a 'tag' which enables me to find out the width and the heigth of an gif/jpg image?
I would like to store this information into the database.

+ what can you suggest?
Do you think, for performance reason is it better NOT to store my image in a SQl server database? Or is it better to store the image in a SQL server database?

Thanks for help!
bram
 
in javascript (for specific browser targetting go & read the doc at devedge or msdn)
---
<img src=... id=&quot;any_id&quot; ....>
....

var img_width = document.any_id.width
same for height
 
So Bram, you'd need to use CFDIRECTORY to query the files you want to put into your database, output that query to create hidden form parameters, again in a javascript tag to prepare some images, and once again to run a javascript function for every record to set those hidden parameters.

1. Loop through your output in the page, accept only files (not . or .. which are directories) where listGetAt(name,2,&quot;.&quot;) is &quot;jpg&quot; or &quot;gif&quot; (image files). Create 3 hidden parameters for each record returned (name,width,height).


<html>
<form name=&quot;theForm&quot;>
<CFSET incr=0>
<CFOUTPUT query=&quot;theDirectoryQuery&quot;>
<CFIF type is not &quot;dir&quot; AND name is not &quot;.&quot; AND name is not &quot;..&quot;>
<CFIF listContainsNoCase(name, &quot;gif&quot;) OR listContainsNoCase(name, &quot;jpg&quot;)>
<CFSET incr=incr+1>
<!-- inputs for #incr# -->
<input type=&quot;hidden&quot; name=&quot;imgName#incr#&quot; value=&quot;#trim(lcase(name))#&quot;>
<input type=&quot;hidden&quot; name=&quot;imgW#incr#&quot; value=&quot;&quot;>
<input type=&quot;hidden&quot; name=&quot;imgH#incr#&quot; value=&quot;&quot;>
</CFIF>
</CFIF>
</CFOUTPUT>
</form>
</html>

2. Use a javascript function to set the values of those hidden parameters. To do this, first prep a variable for each image using the #incr# variable. Then execute the function once for every record. Take out the alert() when you're done debugging.

<script language=&quot;javascript&quot;>
<!--

doc = document.forms[&quot;theForm&quot;];
<CFSET incr = 0>
<CFOUTPUT query=&quot;theDirectoryQuery&quot;>
<CFSET incr=incr+1>
var img#incr# = new Image();
img#incr#.src = '#trim(lcase(name))#';
</CFOUTPUT>

<CFSET incr = 0>
<CFOUTPUT query=&quot;theDirectoryQuery&quot;>
<CFSET incr=incr+1>
go(#incr#);
</CFOUTPUT>

function go(n)
{
var temp = eval('img' + n);

//width
var hidParamW = 'imgW' + n;
doc[hidParamW].value = temp.width;

//height
var hidParamH = 'imgH' + n;
doc[hidParamH].value = temp.height;

//test
alert('width: ' + doc[hidParamW].value + ' height: ' + doc[hidParamH].value);


}
//-->
</script>


Once this page is run, your result will be 3 hidden form parameters for every file returned in the query. Their values will be set, and you'll then need to submit that form and populate your database accordingly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top