Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify extent background color? #415

Open
Jakobud opened this issue Jun 19, 2015 · 13 comments
Open

How to specify extent background color? #415

Jakobud opened this issue Jun 19, 2015 · 13 comments
Labels

Comments

@Jakobud
Copy link

Jakobud commented Jun 19, 2015

According to the docs, extent's description is:

composite image on background color canvas image.

The usage is:

gm("img.png").extent([width, height, options])

How do you use this function? Where do you specify the background color of the image.

The problem I'm trying to solve is converting a PNG (with transparency) to a JPG. By default, the transparent color gets filled with black. I'm trying to figure out how to fill it with a different color and I'm assuming I need to composite the image on top of another blank color canvas before saving the output image.

@rwky rwky added the question label Jul 9, 2015
@tingfengainiaini
Copy link

Have you solved this problem ? Now I am confusing with this.

@Jakobud
Copy link
Author

Jakobud commented Aug 13, 2015

I have no idea how to solve this. The problem is when I convert a PNG with a transparent background to a JPG. The script fills in the transparent background with black by default. I can't figure out how to specify a different background color.

@tingfengainiaini
Copy link

I use the GM with C++. As you said, finally I put the png on the top of another canvas with needed color. I use the composite function. And this sovled this problem.
This solution based on that, in the Gm's command line to do this job:
gm convert input.png -flatten output.jpg
I seeked into the "convert" command source code, the flatten parameter deals with image sequences, but if with one image as input, the GM would new a blank canvas as its background.So, my conclusion is the "composite" way. I am not sure my conclusion right or not. I am poor in C++, and in English, sorry about that.

@tingfengainiaini
Copy link

In the GM, there exit two functions, backgroundColor(Color) and matteColor(Color), I have tried both, but no help.

@mikemonteith
Copy link

I've been struggling with this too. Finally realised you have to "flatten" the png

gm("img.png").background('red').flatten().toFormat('jpg');

@tingfengainiaini
Copy link

But there is no flatten() function in GM's C++ usage.

@mikemonteith
Copy link

@tingfengainiaini
Copy link

Aha. This function is what I need. When I do this to a png image, I got a jpg file with white background color:
image = FlattenImages(image,&exception);
However, it's a c function, and the parameter image is also a MagickLib::_Image. I use the GM's C++ interface. So, there should be a class converting problem.
And, what is more interesting is, this function is FlattenImages, not FlattenImage. The user manual make a mistake.

@Jakobud
Copy link
Author

Jakobud commented Aug 20, 2015

So how do you do this with this gm plugin?

@mikemonteith
Copy link

@Jakobud

gm("img.png").background('#FF0000').flatten().toFormat('jpg');

@kapouer
Copy link
Contributor

kapouer commented Sep 24, 2015

Hey, @rwky only flatten is documented on http://aheckmann.github.io/gm/docs.html

@digz6666
Copy link

digz6666 commented Dec 6, 2015

@mikemonteith toFormat method is not defined:

Exception in callback of async function: TypeError: Object [object Object] has no method 'toFormat'

@mikemonteith
Copy link

@digz6666 I'm not sure where I got toFormat from 😟
It should be .setFormat('jpg'); to explicitly set the output format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants