如何使用 cfimage 处理跳过不支持的图像?
How to skip unsupported image using cfimage processing?
我正在使用 ColdFusion 10。
尝试读取某些图像文件时,ColdFusion returns 未显示任何值和错误消息。
我尝试使用 cfimage 标签调整图像大小。它正在崩溃。所以我尝试使用 "imageinfo" 函数获取有关图像的信息。它 returns 空白。请帮我获取一些信息或跳过图像。谁能帮帮我?
我尝试使用
读取导致异常的文件
<cfimage action="read" source="full pathname" name="image">
<cfset image = imageRead(full pathname)>
和许多其他 ColdFusion 记录的函数。没有显示错误。没有获得输出。我使用了显示不支持的文件类型错误的 cffile。
<cffile
action = "readBinary" file = "full pathname" variable = "variable name"
>
谢谢里诺
尝试使用此功能读取图像。
<cfimage>
标签或 imageNew()
在上传时尝试读取损坏的图像文件或使用更改的扩展名保存的文件(背景透明的 .png 文件保存为 .jpeg)时可能会出现问题。
我认为这些文件的主要问题是当我们尝试读取上述文件时,coldfusion 有可能不会抛出任何类型的错误。
<cfscript>
public function readImage(fullpath){
//trying java imageio
var imageFile = createObject("java", "java.io.File").init(fullpath);
// read the image into a BufferedImage
var ImageIO = createObject("java", "javax.imageio.ImageIO");
try {
var bi = ImageIO.read(imageFile);
return ImageNew(bi);
} catch(any e) {
//try for bad formatted images
//create java file object, passing in path to image
var imageFile = createObject("java","java.io.File").init(fullpath);
//create a FileSeekableStream, passing in the image file we created
var fss = createObject("java","com.sun.media.jai.codec.FileSeekableStream").init(imageFile);
//create ParameterBlock object and initialize it (call constructor)
var pb = createObject("java","java.awt.image.renderable.ParameterBlock").init();
//create JAI object that will ultimately do the magic we need
var JAI = createObject("java","javax.media.jai.JAI");
try {
//pass in FileSeekableStream
pb.add(fss);
//use the JAI object to create a buffered jpeg image.
var buffImage = local.JAI.create("jpeg", pb).getAsBufferedImage();
//pass the buffered image to the ColdFusion imagenew()
var New_Image = imagenew(buffImage);
//make sure we close the stream
fss.close();
return New_Image;
} catch (any e) {
if (isDefined("fss")) {
fss.close();
}
rethrow;
}
}
}
</cfscript>
我正在使用 ColdFusion 10。 尝试读取某些图像文件时,ColdFusion returns 未显示任何值和错误消息。
我尝试使用 cfimage 标签调整图像大小。它正在崩溃。所以我尝试使用 "imageinfo" 函数获取有关图像的信息。它 returns 空白。请帮我获取一些信息或跳过图像。谁能帮帮我?
我尝试使用
读取导致异常的文件<cfimage action="read" source="full pathname" name="image">
<cfset image = imageRead(full pathname)>
和许多其他 ColdFusion 记录的函数。没有显示错误。没有获得输出。我使用了显示不支持的文件类型错误的 cffile。
<cffile
action = "readBinary" file = "full pathname" variable = "variable name"
>
谢谢里诺
尝试使用此功能读取图像。
<cfimage>
标签或 imageNew()
在上传时尝试读取损坏的图像文件或使用更改的扩展名保存的文件(背景透明的 .png 文件保存为 .jpeg)时可能会出现问题。
我认为这些文件的主要问题是当我们尝试读取上述文件时,coldfusion 有可能不会抛出任何类型的错误。
<cfscript>
public function readImage(fullpath){
//trying java imageio
var imageFile = createObject("java", "java.io.File").init(fullpath);
// read the image into a BufferedImage
var ImageIO = createObject("java", "javax.imageio.ImageIO");
try {
var bi = ImageIO.read(imageFile);
return ImageNew(bi);
} catch(any e) {
//try for bad formatted images
//create java file object, passing in path to image
var imageFile = createObject("java","java.io.File").init(fullpath);
//create a FileSeekableStream, passing in the image file we created
var fss = createObject("java","com.sun.media.jai.codec.FileSeekableStream").init(imageFile);
//create ParameterBlock object and initialize it (call constructor)
var pb = createObject("java","java.awt.image.renderable.ParameterBlock").init();
//create JAI object that will ultimately do the magic we need
var JAI = createObject("java","javax.media.jai.JAI");
try {
//pass in FileSeekableStream
pb.add(fss);
//use the JAI object to create a buffered jpeg image.
var buffImage = local.JAI.create("jpeg", pb).getAsBufferedImage();
//pass the buffered image to the ColdFusion imagenew()
var New_Image = imagenew(buffImage);
//make sure we close the stream
fss.close();
return New_Image;
} catch (any e) {
if (isDefined("fss")) {
fss.close();
}
rethrow;
}
}
}
</cfscript>