yihui / animation

A gallery of animations in statistics and utilities to create animations

Home Page:https://yihui.org/animation/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adjust size when contucting "im.convert()"

gongyixiao opened this issue · comments

Hi, there,

Thanks for developing this tool for the community.

I'm using im.convert(input, output=output,extra.opts="-density 150") to convert pdf to png files. Is there a way to define the size of the png file (width and height)? Maybe in the "extra.ops" option? But I can't find information from the documentation.

Thanks.

Yixiao

Hi Yixiao,

I read ImageMagick manual, maybe you should try using option -resize, please see http://www.imagemagick.org/script/command-line-options.php#resize.

im.convert(input, output=output,extra.opts="-density 150 -resize '200%'")
NOTE: I didn't test it.

Hi, Lijia,

Thanks for the quick respond. I tested your suggestion it actually works pretty well. But here is an small issue:

The command I use is:

im.convert(input, output=output,extra.opts="-density 150 -resize '20%'")

which trying to shrink the image, but the .png file becomes bigger than if I don't use "-resize '20%'", like 2 times bigger. Do you know why?

Thanks.

Yixiao

I convert a pdf file to png file and shrink the image at the same time, it works fine. If you still have trouble with your data, please upload your data, I need reproduce this bug.

Maybe I didn't describe it very well. I used the command I mentioned before, it converted the pdf to png, and it is smaller in terms of the size of the image. But, comparing with using -resize 100%, the actual file size of the .png file became 2 times bigger. I believe you can use any pdf to test it.

Thanks.

OK. I upload my test files.

## input file, please see https://github.com/yulijia/animation/blob/issue83/mtcars.pdf


im.convert("mtcars.pdf",output="TEST100.png",extra.opts = "-resize '100%'")
## output file, please see https://github.com/yulijia/animation/blob/issue83/TEST100.png
## the figure size of the .png file is the same size of the .pdf file

im.convert("mtcars.pdf",output="TEST200.png",extra.opts = "-resize '200%'")
## output file, please see https://github.com/yulijia/animation/blob/issue83/TEST200.png
## the figure size of the .png file is 2 times bigger  than the .pdf file

im.convert("mtcars.pdf",output="TEST20.png",extra.opts = "-resize '20%'")
## output file, please see https://github.com/yulijia/animation/blob/issue83/TEST20.png
## the figure size of the .png file is resize to 20%

im.convert("/root/mtcars.pdf",output="TEST150.png",extra.opts = "-density 150")
## output file, please see https://github.com/yulijia/animation/blob/issue83/TEST150.png
## the figure size of the .png file is 2 times bigger than the .pdf file

im.convert("/root/mtcars.pdf",output="TEST150100.png",extra.opts = "-density 150 -resize '100%'")
## output file, please see https://github.com/yulijia/animation/blob/issue83/TEST150100.png
## the figure size of the .png file is 2 times bigger than the .pdf file

If you use -density 150 -resize 100% in the same time, please make sure your original figure default resolution is 150 dots per inch, then you can get a same size output figure.

However the default resolution of most figure is 72 dots per inch in our computers. So you find the output figure is larger than the original.

For more information, please read the ImageMagick manual density part, http://www.imagemagick.org/script/command-line-options.php#density

Feel free to reopen this issue if you think you have encountered a bug in animation package.