使用 CF8 cfimage 标签生成缩略图 - 由图像元数据引起的大文件 [英] generating thumbnails using CF8 cfimage tag - large filesize caused by image metadata

查看:32
本文介绍了使用 CF8 cfimage 标签生成缩略图 - 由图像元数据引起的大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个小型网络应用程序,该应用程序将在上传后将图像调整为不同的像素尺寸.

i'm building a small web app that will resize images to different pixel dimensions after they have been uploaded.

我正在尝试从 3mb jpg 图像创建 150px X 100px 缩略图,但无法获得小于 68kb 的文件大小(我希望根据压缩类型等生成 4kb 和 15kb 文件之间的文件).

I am attempting to create 150px X 100px thumbnail from a 3mb jpg image, but am unable to get the filesize smaller than 68kb ( I would expect to generate a file between 4kb & 15kb file depending on compression type etc).

我使用了标签的 action="resize" 方法 &还使用了 ImageResize() &imageScaleToFit() 函数,但所有这些方法都保留了 exif &IPTC 元数据完好无损(我假设这就是使缩略图文件保持尽可能大的原因).

I have used the action="resize" method of the tag & also used the ImageResize() & imageScaleToFit() functions but all these methods keep the exif & IPTC meta data intact (I am assuming this is what is keeping the thumbnail file as large as it is).

如果我使用没有任何元数据的图像,它会按预期将缩略图大小调整为较小的文件大小.

If I use an image without any metadata it resizes the thumbnail to a small filesize as expected.

无论如何我可以剥离exif &使用 CF8 的任何内置图像函数从图像中获取 IPTC 元数据以减小缩略图大小?

Is there anyway I can strip the exif & IPTC metadata from the image to reduce the thumbnail size using any of CF8's built in image functions?

推荐答案

您可以使用 Sanselan用于删除 EXIF 和 IPTC 元数据的 Java 库.以下是使用此库中的 removeExifMetadata 的代码示例:

you can use the Sanselan Java library to remove EXIF and IPTC metadata. Here is a code sample using the removeExifMetadata from this library:

<cfscript>
// setup and init the Sanselan library
SanselanPath = arrayNew(1);
arrayAppend(SanselanPath, expandPath("sanselan\sanselan-0.97-incubator.jar"));
javaloader = createObject("component", "javaloader.JavaLoader").init(SanselanPath);

// setup your source and destination image
pathToInFile = ExpandPath("myImage.jpg");
pathToOutFile = ExpandPath("MyImagewoEXIF.jpg");
inFile = javaloader.create("java.io.FileInputStream").init(pathToInFile);
outFile = javaloader.create("java.io.FileOutputStream").init(pathToOutFile);

// create the exifRewriter 
exifRewriter = javaloader.create("org.apache.sanselan.formats.jpeg.exifRewrite.ExifRewriter").init();

// call the method removeExifMetadata
exifRewriter.removeExifMetadata(inFile,outFile);
outFile.close();
</cfscript>

您可以使用 iptc.JpegIptcRewriterremoveIPTC 方法来删​​除 IPTC 元数据.您可以使用 CF 函数 ImageGetEXIFMetaData 和 ImageGetIPTCMetadata 验证是否已删除所有内容.

You can do the same to remove IPTC meta data using iptc.JpegIptcRewriter and the removeIPTC method. You can verify using the CF functions ImageGetEXIFMetaData and ImageGetIPTCMetadata that everything has been removed.

现在我不确定它是否真的会减小文件大小,请告诉我:-)

Now I'm not sure that it will really reduce the file size, let me know :-)

这篇关于使用 CF8 cfimage 标签生成缩略图 - 由图像元数据引起的大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆