Last active
August 29, 2015 14:01
-
-
Save ilyakava/1486672d367b4b1654ce to your computer and use it in GitHub Desktop.
gm4java - trying to get multiple images in 1 gm process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Failed attempts to process several images within a single gm process | |
// some of these are silly, but I was desperate | |
val config = new GMConnectionPoolConfig() | |
val service = new PooledGMService(config) | |
val command = new GMBatchCommand(service, "convert") | |
// Q1. can we make GMBatchCommand run an operation with multiple images in it? | |
val a = Files.createTempFile("thumbnail", ".jpg").toString | |
val aa = Files.createTempFile("thumbnail", ".jpg").toString | |
val op1 = new GMOperation() | |
op1.addImage("/Users/artsyinc/Documents/doublet/test_images/100_w_matt/grioc0000030-D.jpg") | |
op1.resize(200, 200) | |
op1.addImage(a) | |
op1.addImage("/Users/artsyinc/Documents/doublet/test_images/100_w_matt/grioc0001416-D.jpg") | |
op1.resize(200, 200) | |
op1.addImage(aa) | |
command.run(op1) | |
// A. | |
// org.im4java.core.CommandException: org.im4java.core.CommandException: convert: Empty input file (/var/folders/sz/v9p5w7d912182q3mtj_gy_j40000gp/T/thumbnail983933003158565220.jpg). | |
// This is the 2nd tmp image | |
// Q2. can we do the above with an explicit convert statement? | |
val b = Files.createTempFile("thumbnail", ".jpg").toString | |
val bb = Files.createTempFile("thumbnail", ".jpg").toString | |
val op2 = new GMOperation() | |
op2.addImage("/Users/artsyinc/Documents/doublet/test_images/100_w_matt/grioc0000030-D.jpg") | |
op2.resize(200, 200) | |
op2.addImage(b) | |
op2.addRawArg("convert") | |
op2.addImage("/Users/artsyinc/Documents/doublet/test_images/100_w_matt/grioc0001416-D.jpg") | |
op2.resize(200, 200) | |
op2.addImage(bb) | |
command.run(op2) | |
// A. | |
// org.im4java.core.CommandException: java.io.IOException: convert: Unable to open file (convert) [No such file or directory]. | |
// Q3. will the run method for GMBatchCommand take several GMOperation arguments | |
// A. | |
// java.lang.IllegalArgumentException: more argument images than placeholders! | |
// Q4. will the run method for GMBatchCommand take a linked list of arguments? | |
// A. | |
// <console>:31: error: type mismatch; | |
// found : java.util.LinkedList[org.gm4java.im4java.GMOperation] | |
// required: org.im4java.core.Operation | |
// command.run(opss) | |
// Q5. can we add multiple commands in sequence to a PooledGMService? | |
val t = Files.createTempFile("thumbnail", ".jpg").toString | |
val tt = Files.createTempFile("thumbnail", ".jpg").toString | |
service.execute("convert", | |
"/Users/artsyinc/Documents/doublet/test_images/100_w_matt/grioc0000030-D.jpg", | |
"-resize", | |
"200x200", | |
t, | |
"/Users/artsyinc/Documents/doublet/test_images/100_w_matt/grioc0001416-D.jpg", | |
"-resize", | |
"200x200", | |
tt) | |
// A. | |
// org.gm4java.engine.GMException: convert: Empty input file (/var/folders/sz/v9p5w7d912182q3mtj_gy_j40000gp/T/thumbnail4276570003656926961.jpg) | |
// This is the 2nd tmp image | |
// Q6. Should I repeat the above with an extra "convert" argument? | |
val n = Files.createTempFile("thumbnail", ".jpg").toString | |
val nn = Files.createTempFile("thumbnail", ".jpg").toString | |
service.execute("convert", | |
"/Users/artsyinc/Documents/doublet/test_images/100_w_matt/grioc0000030-D.jpg", | |
"-resize", | |
"200x200", | |
n, | |
"convert", | |
"/Users/artsyinc/Documents/doublet/test_images/100_w_matt/grioc0001416-D.jpg", | |
"-resize", | |
"200x200", | |
nn) | |
// A. | |
// java.io.IOException: convert: Unable to open file (convert) [No such file or directory]. | |
// Q7. can we execute the batch command explicitly? | |
val v = Files.createTempFile("thumbnail", ".jpg").toString | |
val vv = Files.createTempFile("thumbnail", ".jpg").toString | |
service.execute("batch", "convert", "/Users/me/test_images/grioc0000030-D.jpg", "-resize", "200x200", v, "convert", "/Users/me/test_images/grioc0001416-D.jpg", "-resize", "200x200", vv) | |
// A. | |
// org.gm4java.engine.GMException: gm: Unrecognized command 'batch'. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A1: It's not about how many image files, one GMOperation should be exactly one GM command. In this case, you can only add as much as what you can enter in one convert command. But you can reuse GMOperation instance with different images, see im4java documentation for detail.
A2: No, you cannot, for the same reason as Q1.
A3, A4: See documentation http://im4java.sourceforge.net/api/org/im4java/core/ImageCommand.html#run%28org.im4java.core.Operation,%20java.lang.Object...%29
A5, A6, A7: One execute call is strictly one GM command. If you need to execute multiple commands, make multiple calls.