im4java学习---阅读documentation文档
Utilities----im提供的一些工具类
①、读取图片文件信息---Info类
我们之前的做法:
op.format("width:%w,height:%h,path:%d%f,size:%b%[EXIF:DateTimeOriginal]");
IdentifyCmd identifyCmd = new IdentifyCmd(useGM);
使用工具类Info:
Info imageInfo = new Info(filename,true);
System.out.println("Format: " + imageInfo.getImageFormat());
System.out.println("Width: " + imageInfo.getImageWidth());
System.out.println("Height: " + imageInfo.getImageHeight());
System.out.println("Geometry: " + imageInfo.getImageGeometry());
System.out.println("Depth: " + imageInfo.getImageDepth());
System.out.println("Class: " + imageInfo.getImageClass());
第二个参数true,表示只获取图片的基本信息。
***这个工具类,在1.3.0版本之前,方法实现有问题。针对TIF和GIF图片,
imageInfo.getImageWidth() 返回的是第一帧的图片宽度(原文是first scene)
这个问题我也不懂,只是写出来下,大家都注意下,详细的还是看文档吧。
②、读取某个目录下所有指定后缀的图片文件---FilenameLoader类
你还在用这种批量图片处理方式么?
public void resizeImages(String... pImageNames)
恭喜你,out了。嘿嘿,开玩笑^-^
让我们来看下新的方法:
ExtensionFilter filter = new ExtensionFilter("jpg"); //指定后缀
filter.setRecursion(true); //递归扫描
filter.ignoreDotDirs(true); //忽略那些带点的隐藏目录(此处是个人说法,看到过,Android手机里很多这目录,但是不懂到底怎样命名)
FilenameLoader loader = new FilenameLoader(filter);
List<String> files = loader.loadFilenames(mydir); //mydir文件夹路径
这个类在API文档中有详细介绍。
③、既然有批量转换,我们也需要命令这一大堆目标文件的名称---FilenamePatternResolver类
// define operation and command
IMOperation op = new IMOperation();
op.addImage(); // input-file
op.addImage(); // output-file
ConvertCmd cmd = new ConvertCmd(); // load files
ExtensionFilter filter = new ExtensionFilter("jpg");
FilenameLoader loader = new FilenameLoader(filter);
List<String> files = loader.loadFilenames(mydir); // create the resolver-----看这里,baby go
FilenamePatternResolver resolver =
new FilenamePatternResolver("%P/%f.tif"); // now iterate over all files
for (String img:files) {
cmd.run(op,img,resolver.createName(img));
}
个人理解:你不用每次都拼凑目标图片名字了,有很便利的方法实现。
- %P: full pathname of source-image (i.e. the directory)
- %p: last component of %P(用于相对路径?)
- %F: full filename without directory part
- %f: filename without directory part and extension
- %e: only the extension
- %D: drive-letter (on windows systems). Not available for source-files with an UNC-name.(盘符C:...)
这样就好理解 new FilenamePatternResolver("%P/%f.tif");了,就是绝对目录路径+文件名+tif
④、Debugging--窝不是类,只是一种操作方法
版本号>1.0,这个一般都是成立的。
IMOperation op = new IMOperation();
...
ConvertCmd cmd = new ConvertCmd();
cmd.createScript("myscript.sh",op);
没错,就是它了。把最后要执行的cmd+op备份到myscrip.sht脚本中。
在windows下,createScript()生成的脚本会自动加上 .bat 后缀
⑤、批量转换处理(适用于客户端程序,不适合web-application)
ExtensionFilter filter = new ExtensionFilter("jpg");
filter.setRecursion(false);
FilenameLoader loader = new FilenameLoader(filter);
List<String> images=loader.loadFilenames(dir);
After you have the list, you create your BatchConverter and use it's run()-method
to process the images:
// create a simple thumbnail operation
op = new IMOperation();
op.size(80);
op.addImage(); // placeholder input filename
op.thumbnail(80);
op.addImage(); // placeholder output filename // create a template for the output-files:
// we put them in targetDir with the same filename as the original
// images
String template=targetDir+"%F"; // create instance of BatchConverter and convert images-----看这里,baby go
BatchConverter bc = new BatchConverter(BatchConverter.Mode.PARALLEL);
bc.run(op,images,targetDir+"%F");
BatchConverter有三种执行模式:BatchConverter.SEQUENTIAL, BatchConverter.PARALLEL,BatchConverter.BATCH。
分别为顺序处理,并行处理(CPU多核),批处理(单核)
最后,还是推荐大家去看下官方英文文档,本人水平有限,本着交流的精神,所以才发帖献丑一番,主要是为了记录自己的学习过程。
im4java学习---阅读documentation文档的更多相关文章
- Emacs阅读chm文档
.title { text-align: center; margin-bottom: .2em } .subtitle { text-align: center; font-size: medium ...
- 阅读MDN文档之CSS选择器介绍(一)
本文为阅读MDN文档笔记 目录 Different types of Selectors Attribute Selectors Presence and value attribute select ...
- MongoDB学习笔记:文档Crud Shell
MongoDB学习笔记:文档Crud Shell 文档插入 一.插入语法 db.collection.insertOne() 将单个文档插入到集合中.db.collection.insertMan ...
- redis module 学习—官网文档整理
前言 redis在4.0版本中,推出了一个非常吸引的特性,可以通过编写插件的模式,来动态扩展redis的能力.在4.0之前,如果用户想拥有一个带TTL的INCRBY 命令,那么用户只能自己去改代码,重 ...
- apidoc学习(接口文档定义取代word)
apidoc的安装,参考:https://blog.csdn.net/qq_36386771/article/details/82149848 生产文档,需要先编写一个apidoc.json对接口文档 ...
- ElasticSearch 5学习(8)——分布式文档存储(wait_for_active_shards新参数分析)
学完ES分布式集群的工作原理以及一些基本的将数据放入索引然后检索它们的所有方法,我们可以继续学习在分布式系统中,每个分片的文档是被如何索引和查询的. 路由 首先,我们需要明白,文档和分片之间是如何匹配 ...
- 阅读MDN文档之StylingBoxes(五)
目录 BoxModelRecap Box properties Overflow Background clip Background origin Outline Advanced box prop ...
- 使用perldoc阅读perl文档
perl在安装的时候,就给我们送上一份大礼,组织精美,解释详细的perl百科全书已经安装在你的电脑里面了,遇到问题不要在去搜索那些博客了,还是练练英文,看看perldoc吧,呵呵. 1.用perldo ...
- python 学习之FAQ:文档内容写入报错
2017.3.29 FAQ 1. 文档内容写入报错 使用with open() as file: 写入文档时,出现'\xa9'特殊字符写入报错,通过print('\xa9')打印输出“©”. > ...
随机推荐
- mono webreques https exception
前几天在做一个使用URL通过WebRequest请求HTML页面的功能的时候遇到了点坑,程序在开发环境没有任何的问题,部署到linux mono上之后就跪了.代码如下: public static s ...
- 实用脚本 4 -- Makefile(不同文件下的多个可执行文件or静态库编译到同一目录下)
不同文件下的多个可执行文件编译到同一目录下,这样方便观察编译结果,从而方便进程操作.使用时根据自己的需要在进行局部修改(如 链接库.目标文件等等). 1..bashrc 中设置编译主目录(例如) ex ...
- NodeJS微信公众平台开发
微信是手机用户必备的App,微信最开始只是作为社交通讯应用供用户使用,但随着用户量不断的增加,微信的公众号在微信上表现出来了它强大的一面,微信公众平台具有四大优势:1.平台更加稳固:2.用户关系更加平 ...
- 基于Ubuntu搭建Linux路由器
开源,几乎代表了无所不能的意思,最近又因为它玩Hi了... 因业务发展,需要临时接入300MB的专线和千兆路由器,而公司现有的路由器却是百兆的,出于成本考虑,只能不想更换新的路由器,在网上查了一下可以 ...
- [译]Python - socket.error: Cannot assign requested address
原文来源: https://stackoverflow.com/questions/48306528/python-socket-error-cannot-assign-requested-addre ...
- idea 快捷键(复制)
Ctrl+Shift + Enter,语句完成“!”,否定完成,输入表达式时按 “!”键Ctrl+E,最近的文件Ctrl+Shift+E,最近更改的文件Shift+Click,可以关闭文件Ctrl+[ ...
- ios UI自动化测试学习笔记
一.一些注意事项: 1.做自动化测试时注意如果是真机话首先要设置不锁屏. 2.自动化测试过程中如果程序后台或崩溃了.脚本运行将会暂停,直到程序再次回到前台. 3.必须明确指定关闭自动测试,测试完成或中 ...
- Java课程设计--学生成绩管理系统
一.团队名称: 团队成员 林艺薇 201721123032 网络1712 黄毓颖 201721123033 网络1712 唐川 201721123034 网络1712 梁才玉 201721123038 ...
- webstorm-前端javascript开发神器中文教程和技巧分享(转)
webstorm是一款前端javascript开发编辑的神器,此文介绍webstorm的中文教程和技巧分享. webstorm8.0.3中文汉化版下载: 百度网盘下载:http://pan.baidu ...
- PokeCats开发者日志(四)
现在是PokeCats游戏开发的第八天的上午,感觉游戏做得差不多了,来写一下开发者日志吧! (1)增加闯关模式,一共30关. (2)更改了最后一关的主题,更换了背景,将树桩改为礼物盒. ...