|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
image size setup
Author: daniel kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56376#305268
>Sorry, yes... it removes anything that isn't a letter, number, underscore or
>hyphen
>
Very nice = thank you very much
Author: Bobby Hartsfield
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56376#305267
Sorry, yes... it removes anything that isn't a letter, number, underscore or
hyphen
You could add dots to it as well if you want to run it against the whole
name including the extenstion...
[^a-zA-Z0-9-_\.]
So this:
Rereplace('joe_smiling (small).jpg', '[^a-zA-Z0-9-_\.]', '_', 'all')
Would result in:
joe_smiling__small_.jpg
.:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
http://cf4em.com
>A safe bet would be rereplace [^a-zA-Z0-9-_]
Thank you very much.
I want to just implement it without getting it, but I can't. What would
that clear out? My guess is that it only allows a-z (and caps) and 0 to 9
(and maybe dash).
I do appreciate the help.
Author: daniel kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56376#305265
>A safe bet would be rereplace [^a-zA-Z0-9-_]
Thank you very much.
I want to just implement it without getting it, but I can't. What would that
clear out? My guess is that it only allows a-z (and caps) and 0 to 9 (and maybe
dash).
I do appreciate the help.
Author: Bobby Hartsfield
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56376#305262
A safe bet would be rereplace [^a-zA-Z0-9-_]
.:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
http://cf4em.com
Thank you everyone - it's working now.
I have a related question, though it's not about referencing. It seems that
now that I'm going through java, the images often can't be read because
their title contains odd characters - characters that are fine in CF, for
example "joe_smiling (small).jpg". In this case the parens mess it up, but
I'm not sure what else might.
Clearly I should cleanse the image name on the way in. I don't work in java
much, so I'm not sure which chars to replace. I have something that
cleanses chars but it's not useful for this.
I've been googling for illegal path characters but haven't found a list
yet.
daniel
Author: daniel kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56376#305258
Thank you everyone - it's working now.
I have a related question, though it's not about referencing. It seems that now
that I'm going through java, the images often can't be read because their title
contains odd characters - characters that are fine in CF, for example
"joe_smiling (small).jpg". In this case the parens mess it up, but I'm not sure
what else might.
Clearly I should cleanse the image name on the way in. I don't work in java
much, so I'm not sure which chars to replace. I have something that cleanses
chars but it's not useful for this.
I've been googling for illegal path characters but haven't found a list yet.
daniel
Author: Adrian Lynch
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56376#305237
If set_size needs a reference to the image object, return the image object
from init_image and then pass it to the set_size function.
Adrian
http://www.adrianlynch.co.uk/
Recently, someone has posted how to check image sizes using java in
CF. I have hundreds of images to check on one page where the images
are entered by users. On the code that was posted, a java object is
created and then a pict is assigned to it. It would seem that since
I am doing lots of images, I shouldn't create an image object each
time, just the picture object (f). So I broke them into two batches
of script, but I'm getting the error stating that imgRdr is undefined
(cause it's in another function). I'm not sure how to reference this
var or if the rest of this is gonna work or if it's a good idea at
all. Any thoughts?
Here's the code:
<cfscript>
function init_image (){
imgObj = CreateObject
("java","java.awt.image.BufferedImage");
imgRdr = CreateObject
("java","javax.imageio.ImageIO");
}
function set_size(image_name){
f = CreateObject("java","java.net.URL").init
('http://www.sph.umd.edu/images/careerexpo.jpg');
imgObj = imgRdr.read(f);
imgObj.imageWidth = imgObj.getWidth();
imgObj.imageHeight = imgObj.getHeight();
return imgObj;
}
</cfscript>
--
Daniel Kessler
University of Maryland College Park
School of Public Health
3302E HHP Building
College Park, MD 20742-2611
Phone: 301-405-2545
http://sph.umd.edu
Author: Bobby Hartsfield
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56376#305233
Wow... that looks eerily familiar to this...
/*
* Returns image height, width and file size (kb, kB, mB)
*
* @param imgfile Absolute path to a valid image file
(Required)
* @param appname Application name. (Required)
* @return Returns a struct.
* @author Bobby Hartsfield (bobby@acoderslife.com)
* @version 3
* @created May 8, 2006
*/
function bhimginfo(imgfile){
var jFileIn = createObject("java","java.io.File").init(imgfile);
var ImageObject =
createObject("java","javax.imageio.ImageIO").read(jFileIn);
var ImageInfo = StructNew();
var imageFile = CreateObject("java", "java.io.File").init(imgfile);
var sizeb = imageFile.length();
var sizekb = numberformat(sizeb / 1024, "999999999.99");
var sizemb = numberformat(sizekb / 1024, "99999999.99");
var bhImageInfo = StructNew();
bhImageInfo.ImgWidth = ImageObject.getWidth();
bhImageInfo.ImgHeight = ImageObject.getHeight();
bhImageInfo.SizeB = sizeb;
bhImageInfo.SizeKB = sizekb;
bhImageInfo.SizeMB = sizemb;
return bhImageInfo;
}
:-)
Anyway... If you don't need to change it or lose it... just use a persistent
scope for it. Then you can pass it around to whatever you want.
function init_image()
{
application.imgObj = CreateObject("java","java.awt.image.BufferedImage");
application.imgRdr = CreateObject("java","javax.imageio.ImageIO");
}
function set_size(image_name){
f =
CreateObject("java","java.net.URL").init('http://www.sph.umd.edu/images/care
erexpo.jpg');
imgObj = application.imgRdr.read(f);
imgObj.imageWidth = imgObj.getWidth();
imgObj.imageHeight = imgObj.getHeight();
return imgObj;
}
.:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
http://cf4em.com
> Recently, someone has posted how to check image sizes using java in CF.
> This was not posted by me, but it was in response to my query. Works
great. My thanks to the person who first posted it.
<!--- function to get the properties of the image file --->
<cfscript>
function get_imageinfo(imgfile){
jFileIn = createObject("java","java.io.File").init(imgfile);
ImageInfo = StructNew();
ImageObject =
createObject("java","javax.imageio.ImageIO").read(jFileIn);
imageFile = CreateObject("java", "java.io.File");
imageFile.init(imgfile);
sizeb = imageFile.length();
sizekb = numberformat(sizeb / 1024, "999999999.99");
sizemb = numberformat(sizekb / 1024, "99999999.99");
get_imginfo = StructNew();
get_imginfo.ImgWidth = ImageObject.getWidth();
get_imginfo.ImgHeight = ImageObject.getHeight();
get_imginfo.SizeKB = sizekb;
get_imginfo.SizeMB = sizemb;
get_imginfo.ImageFormat = ListLast(ListLast(imgfile, "\"), ".");
}
</cfscript>
<cfset tmp = get_imageinfo("MYPATH\MYFILENAME") /> <!--- this is
the image file to get --->
<cfset width=#get_imginfo.ImgWidth#> <!--- this is
the resulting image width --->
<cfset height=#get_imginfo.ImgHeight#> <!--- this is
the resulting image height --->
<!--- now define what to test width and height against and what to
do --->
<cfif width gt MYMAXWIDTH or height gt MYMAXHEIGHT>
File To Large
<cfelse>
File OK
</cfif>
Robert B. Harrison
Director of Interactive services
Austin & Williams
125 Kennedy Drive, Suite 100 Hauppauge NY 11788
T : 631.231.6600 Ext. 119
F : 631.434.7022
www.austin-williams.com
Author: Robert Harrison
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56376#305231
> Recently, someone has posted how to check image sizes using java in CF.
> This was not posted by me, but it was in response to my query. Works
great. My thanks to the person who first posted it.
<!--- function to get the properties of the image file --->
<cfscript>
function get_imageinfo(imgfile){
jFileIn = createObject("java","java.io.File").init(imgfile);
ImageInfo = StructNew();
ImageObject =
createObject("java","javax.imageio.ImageIO").read(jFileIn);
imageFile = CreateObject("java", "java.io.File");
imageFile.init(imgfile);
sizeb = imageFile.length();
sizekb = numberformat(sizeb / 1024, "999999999.99");
sizemb = numberformat(sizekb / 1024, "99999999.99");
get_imginfo = StructNew();
get_imginfo.ImgWidth = ImageObject.getWidth();
get_imginfo.ImgHeight = ImageObject.getHeight();
get_imginfo.SizeKB = sizekb;
get_imginfo.SizeMB = sizemb;
get_imginfo.ImageFormat = ListLast(ListLast(imgfile, "\"), ".");
}
</cfscript>
<cfset tmp = get_imageinfo("MYPATH\MYFILENAME") /> <!--- this is
the image file to get --->
<cfset width=#get_imginfo.ImgWidth#> <!--- this is
the resulting image width --->
<cfset height=#get_imginfo.ImgHeight#> <!--- this is
the resulting image height --->
<!--- now define what to test width and height against and what to
do --->
<cfif width gt MYMAXWIDTH or height gt MYMAXHEIGHT>
File To Large
<cfelse>
File OK
</cfif>
Robert B. Harrison
Director of Interactive services
Austin & Williams
125 Kennedy Drive, Suite 100 Hauppauge NY 11788
T : 631.231.6600 Ext. 119
F : 631.434.7022
www.austin-williams.com
Author: Daniel Kessler
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56376#305229
Recently, someone has posted how to check image sizes using java in
CF. I have hundreds of images to check on one page where the images
are entered by users. On the code that was posted, a java object is
created and then a pict is assigned to it. It would seem that since
I am doing lots of images, I shouldn't create an image object each
time, just the picture object (f). So I broke them into two batches
of script, but I'm getting the error stating that imgRdr is undefined
(cause it's in another function). I'm not sure how to reference this
var or if the rest of this is gonna work or if it's a good idea at
all. Any thoughts?
Here's the code:
<cfscript>
function init_image (){
imgObj = CreateObject
("java","java.awt.image.BufferedImage");
imgRdr = CreateObject
("java","javax.imageio.ImageIO");
}
function set_size(image_name){
f = CreateObject("java","java.net.URL").init
('http://www.sph.umd.edu/images/careerexpo.jpg');
imgObj = imgRdr.read(f);
imgObj.imageWidth = imgObj.getWidth();
imgObj.imageHeight = imgObj.getHeight();
return imgObj;
}
</cfscript>
--
Daniel Kessler
University of Maryland College Park
School of Public Health
3302E HHP Building
College Park, MD 20742-2611
Phone: 301-405-2545
http://sph.umd.edu
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||