Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
spawninc #1
Image File resolution
hi,
I m currently facing this problem: if i wanna use CFFILE to capture an image
file, in jpg or gif format, how do i know its resolution, for example, 640 x
480.
my work now is to restrict the over-resoluton file to upload to the system, so
i would like to find out what is the best way to identify the image file
resolution and reject this file.
need advise from u guyz, thanx in advanced
spawninc Guest
-
Image resolution
I am trying to print a collage of images on one sheet of paper. When I size my image, how come it appears bigger than it should when I transfer it to... -
CFDocument - Image Resolution
Hey All, I am generating PDF's using CFDocument. All the html type looks excellent, crisp and clean in the PDF's, however any images in the PDF... -
set of resolution for an image
Hi, I'm looking for a way to set the dpi parameter of an image in order to control the size of the print out knowing the height and the width of... -
Image resolution on import
I have open an RGB AICS document. I link-place a 72ppi JPG. Now ALL that's in the file is a line of Point type and this JPG (whose file size is 80... -
Image resolution changes automatically.
Greetings Tony, For a better understanding of resolution, I suggest you review an excellent article on the subject. Please visit the Digital Dog... -
BSterner #2
Re: Image File resolution
If you're running MX+, you could use of the [url]http://java.sun.com/products/java-media/jai/[/url]
BSterner Guest
-
BSterner #3
Re: Image File resolution
If you're running MX+, you could use of the [url]http://java.sun.com/products/java-media/jai/[/url]. I know you can extract the height and width. Not sure about the resolution.
BSterner Guest
-
spawninc #4
Re: Image File resolution
i only hv less control on the server, therefore i will try to use a script to
control the image file instead. I will restrict the image file that its width
is more than 300 pixl to upload to the server, so how can i achieve this?
spawninc Guest
-
-
bleachedBug #6
Re: Image File resolution
Hi Spawninc
Im afraid I dont know a way of rejecting the image before it is uploaded -
once uploaded thou you could check the width and height of the file with the
following udf:
-------------------------------------------------------------------------------
<cfscript>
/**
* Returns width and height of images based on image type.
*
* @param filename Absolute or relative path to file. (Required)
* @param mimetype Minetype for the file. (Optional)
* @return Returns a struct containing height and width information, or an
error string.
*/
function ImageSize(filename) {
// Jpeg variables
var nFileLength=0; var nBlockLength=0; var nMarker=0;
var nSOI = 65496; // Start of Image (FFD8)
var nEOI = 65497; // End of Image (FFD9)
var nSOF = 65472; // Start of frame nMarker (FFC0)
var nSOF1 = 65473; // Start of frame extended sequential mode (FFC1)
var nSOF2 = 65474; // Start of frame progressive mode (FFC2)
var nSOF3 = 65475; // Start of frame lossless mode (FFC3)
var nSOS = 65498; // Start of Scan (FFDA)
var sImageType = "";
var kCoords = structNew();
var fInput = 0;
var sByte=0;
var sFullPath="";
var sMimeType = "";
if (Left(filename,1) IS "/" OR Left(filename,1) IS "\" OR MID(filename,2,1)
IS ":")
sFullPath=filename;
else
sFullPath=ExpandPath(filename);
// Establish image type
if(arrayLen(arguments) gt 1) { //optional mimetype
sMimeType = arguments[2];
if (LCase(ListFirst(sMimeType,"/")) IS NOT "image") return "Wrong mime type";
if (ListLen(sMimeType,"/") NEQ 2) return "Invalid mime type";
sImageType=LCase(ListLast(sMimeType,"/"));
} else { // work off file extension
if (ListLen(filename,".") LT 2) return "Unknown image type";
sImageType=LCase(ListLast(filename,"."));
}
if(not fileExists(sFullPath)) return "File does not exist.";
//make a fileInputStream object to read the file into
fInput = createObject("java","java.io.RandomAccessFile").in it(sFullPath,"r");
// Get X,Y resolution sizes for each image type supported
switch (sImageType) {
case "jpg": case "jpeg":
do {
nMarker = fInput.readUnsignedShort();
if (nMarker NEQ nSOI AND nMarker NEQ nEOI AND nMarker NEQ nSOS) {
nBlockLength = fInput.readUnsignedShort();
if (nMarker EQ nSOF OR nMarker EQ nSOF1 OR nMarker EQ nSOF2 OR nMarker EQ
nSOF3) { // Start of frame
fInput.readUnsignedByte(); // skip sample precision in bits
kCoords.ImageHeight = fInput.readUnsignedShort();
kCoords.ImageWidth = fInput.readUnsignedShort();
fInput.close();
return kCoords;
} else {
fInput.skipBytes(JavaCast("int",nBlockLength-2));
}
}
} while (BitSHRN(nMarker,8) EQ 255 AND nMarker NEQ nEOI);
break;
case "gif":
fInput.skipBytes(6);
sByte = fInput.readUnsignedByte();
kCoords.ImageHeight = fInput.readUnsignedByte() * 256 + sByte;
sByte = fInput.readUnsignedByte();
kCoords.ImageWidth = fInput.readUnsignedByte() * 256 + sByte;
fInput.close();
return kCoords;
default:
break;
}
//close out this entry
fInput.close();
return "Unhandled image type";
}
</cfscript>
<CFSCRIPT>
kImageSize = ImageSize("D:/Your_Path/Image.jpg");
</CFSCRIPT>
<CFOUTPUT>
#kImageSize.ImageWidth#
#kImageSize.ImageHeight#
</CFOUTPUT>
--------------------------------------------------------------------------------
-------
Hope this helps in some way ;)
Thanks hose
bleachedBug Guest



Reply With Quote

