我使用的是ColdFusion 10。当试图读取一些图像文件时,ColdFusion不返回值,也不显示错误消息。
我试图使用cfimage标记来调整图像的大小。它正在崩溃。所以我试着用的“imageinfo”函数来获取图像的信息。它会返回空白。请帮助我要么得到一些信息,或跳过图像。有谁可以帮我?
我试着读取导致异常的文件
<cfimage action="read" source="full pathname" name="image">
<cfset image = imageRead(full pathname)>以及许多其他ColdFusion文档中的函数。没有显示错误。未获得输出。我使用cffile,它显示了不支持的文件类型错误。
<cffile
action = "readBinary" file = "full pathname" variable = "variable name"
>谢谢里诺
发布于 2015-06-04 13:19:31
尝试使用此函数读取图像。
在上传时,<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>https://stackoverflow.com/questions/30641719
复制相似问题