-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Convert options #566
Convert options #566
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, although maybe it would be more straightforward to have two options, say convertInputOptions and convertOutputOptions, instead of an array with two elements.
This is another thing that I had considered doing to improve png image generation. You got to it first though!
lib/TikZImage.pm
Outdated
@@ -35,7 +35,8 @@ sub new { | |||
tikzLibraries => '', | |||
texPackages => {}, | |||
addToPreamble => '', | |||
ext => 'png', | |||
ext => 'svg', | |||
svgMethod => 'pdf2svg', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this before. The 'convertOptions' should be added here to ensure that they are defined for the object. You are perhaps assuming that this is always used via PGtikz.pl, but that may not be the case. This package can be used directly, in which case the defaults will not be set.
What's your preference?
I could go any way. Maybe it should even be more like:
to generalize better if other tools need options. |
I will let you decide which is best, but I think I prefer |
It also occurred to me that this would be a valid option that a problem author might want to change. So perhaps it would be a good idea to document it in the POD of PGtikz.pl. For example, a problem author could use $graph = createTikZImage();
$graph->ext('png');
$graph->convertOptions([{density => 300}, {quality => 100, resize => "500x500"}]);
$image->BEGIN_TIKZ
...
END_TIKZ This works with your current code, and of course would need to be modified for whatever format you settle on for the option. |
8aae02b
to
0250c19
Compare
I changed the structure to be like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the changes I suggested. Looks good.
@Alex-Jordan #557 was merged, and this now has merge conflicts... so apparently need a bit of work before we can test and merge it. |
0250c19
to
51fce2c
Compare
I rebased and addressed the conflict, then force pushed. (Also rebased and force pushed the corresponding webwork2 PR.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good.
ext => 'svg', | ||
svgMethod => 'pdf2svg', | ||
convertOptions => {input => {},output => {}}, | ||
imageName => '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing my indentation error!
Attached is a test file. The first image |
The SVG in that example is 32KB (at least with my system that is using pdf2svg). The default PNG (with density 300, quality 100) is 35KB. The other PNG that is rescaled to 500x500 is 102KB. I find it interesting that it does not look as good (imho) as the 35KB one. It is fuzzier, some side effect of the rescaling. If I use |
I saw the same thing. The 500x500 image does seem fuzzier. It may be possible to fiddle with the settings and get it a bit better, but I have little confidence in imagemagick's convert to do a good job with this. That is why I highly recommend the svg image when possible. |
Although, I also noted that the second (500x500) png image looks less fuzzy than the first (with your convert defaults) in that example when enlarged. |
If you increase the input density to 500 the image quality improves for the second png, and the file size is less. |
I wonder if we have different versions of ImageMagick and/or latex and that we are seeing different things. For me, among the pngs, the density 300 quality 100 is the clear winner. I can't even distinguish it from the svg without zooming. Here are five versions I'm getting: http://spot.pcc.edu/~ajordan/tikzimages/ |
The files generated on your system are different than those generated on mine. The file sizes are different. However, the file sizes are close, and the visual quality is similar. I think I confused the case with the convert options in defaults.config with the override to no defaults before. I did them at different times in the same place in the problem. Looking again I see something more like you are seeing. One thing to note though is that the density 300 - output 100 options is a 1562x1562 pixel image. So it is really being shrunk to fit the 350x350 output size in the problem. When opened in the image dialog it immediately fills the entire window (since the dialog opens to the natural size limited by the window size). While the resized image opens in the dialog to a more reasonable 500x500 size. I noticed now that if you use Imagemagick's convert has a lot more options to play with, and many of them are not documented. I remember finding some pdf specific options online at one point that can give lossless conversion, but I can't find them anymore. In any case, for usage in the browser svg wins hands down in my opinion. |
I am going to go ahead and merge this. It passes my tests. It has been sitting here for a while now, so I think there has been plenty of time to review. |
This branch follows #557 and should perhaps be rebased once #557 is resolved.
This PR has a counterpart in webwork2: openwebwork/webwork2#1334
This allows the ImageMagick convert command to have options. The options I set for the default:
(1) increase the density that a PDF is carved up into before converting to another image
(2) increase the "quality" (decrease the compression) for building a PNG
The result is PNGs that look pretty good, and only take a little bit more space than the corresponding SVGs in my experiments.
Here is a test file, modified from the earlier PNG SVG comparison file. A line is commented out that sets options. It is commented out with the default options. I suggest seeing what happens when you revert to empty (
[{},{}]
).Note I am not wedded to the default options I set. These are just what PreTeXt settled on for a similar thing, so I started there.