Imagic convert png to jpg to java with im4java

I need to convert from PNG to JPG.

However, iMagick adds a black background to it.

I saw this question , which is for PHP, and tried to write the same for java, like this:

// create the a jpg image
ConvertCmd cmd = new ConvertCmd();
// create the operation, add images and operators/options
IMOperation op = new IMOperation();
op.addImage(brandingURL);
op.format("JPEG");
op.composite();
op.background("white");
op.addImage(imageLocation);
//op.transparent();
// execute the operation
cmd.run(op);

But still the image comes out with a black background.

What am I missing?

+3
source share
2 answers

I had to write the code as follows:

 Info imageInfo = new Info(brandingURL, true);
 IMOperation op = new IMOperation();
 op.addImage(brandingURL);
 op.size(imageInfo.getImageWidth(), imageInfo.getImageHeight());
 op.addImage("xc:white", "c://write//test.jpeg");
 op.addImage("c://write//test.jpeg");
 CompositeCmd composite = new CompositeCmd();
 composite.run(op);
+2
source

backgroundNo call needed. To summarize the documentation , the default background is white, which tells me that maybe one of your shots has a black background that overwrites / blocks by default (maybe the one with brandingURL?).

ImageMagick:

-

.

, -fill. ( ) .

, () , background , ( , ImageMagick wrt )

0

All Articles