-
Notifications
You must be signed in to change notification settings - Fork 94
Parameterize ImageMagick library selection. #33
Conversation
Ah, I'm realizing that there is a very specific way I want #32 done. Effectively, if I tell you how to do it, then I will be writing the code so I guess I should just write the damn code. Sorry for wasting your time on this x_x |
For reference, problems in this current iteration:
|
Thanks for the feedback. To be honest, I am new to javascript/node, so would be happy to use this opportunity to learn. If it's convenient for you to make changes, that's great as well. |
Alright, I can do that |
@@ -2,16 +2,17 @@ | |||
var fs = require('fs'); | |||
var path = require('path'); | |||
var async = require('async'); | |||
var gm = require('gm').subClass({imageMagick: true}); | |||
var gm; |
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.
We are going to want an instance bound gm
to prevent sharing a common gm
instance across different image diffs (e.g. someone might want to run both GraphicsMagick and ImageMagick diffs in the same script)
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.
To do that, we should start accepting options in function ImageDiff
and creating an instance of gm
there.
// Load in `gm` dependency via `require` at the top
var gm = require('gm');
// Inside of the constructor, we adjust `gm` as needed:
function ImageDiff(options) {
var useImageMagick = options.imageMagick === undefined || options.imageMagick;
this.gm = useImageMagick ? gm.subclass({imageMagick: true}) : gm;
}
// Taken from https://github.com/twolfson/twolfson.com/blob/3.4.0/test/perceptual-tests/twolfson.com_test.js#L88-L107 | ||
// TODO: Make image resizing its own library | ||
// DEV: This does not pollute gm.prototype | ||
gm.prototype.fillFromTo = function (params) { |
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.
Unfortunately, this does pollute the prototype now that we can be passing in gm
directly without imageMagick
subclassing. As a result, we should now make this a vanilla function:
function fillFromTo(gm, params) {
gm.borderColor('transparent');
// ...
return gm
}
// When used
fillFromTo(this.gm(actualPath), {
fromWidth: actualSize.width,
fromHeight: actualSize.height,
toWidth: maxWidth,
toHeight: maxHeight
})
Left some comments to resolve, additionally we need to take care of the this.diffCmd = useImageMagick ? 'compare' : 'gm';
this.baseDiffArgs = useImageMagick ? [] : ['compare'];
// Then in the compare call
var diffArgs = this.baseDiffArgs.concat([
'-verbose',
// ...
]) |
Cool, will give a try, thanks! |
I made all the changes except the "compare" call. When I test locally with imageMagick set to false, I stumbled on the same issue that I had faced earlier which triggered this change. The call below creates a one pixel file for expectedTmpPath and actualTmpPath:
Any ideas what could cause this issue? Before these changes, the problem occurred only for ImageMagick library, now I see it happening for GraphicsMagick as well. Thanks. (pushing the code changes for you to get an idea) |
Can you upload the images you are comparing? |
Uploaded the images. What I had discovered was the crop function creates one pixel file if parameters passed are incorrect. |
So does that mean everything is working as expected? |
I don't think so. Image comparison always succeeds no matter what images are because the comparison is taking place between expectedTmpPath and actualTmpPath, both of which are 1 pixel file. This happens in following scenarios: image-diff 1.3.0 on master - issue occurs Not sure what the root cause is. |
Ah, sorry. I meant on the unaltered |
1.3.0/commit d9dc820 has the issue, which is why I started with this approach. |
Ah, I have created a gist to reproduce the issue. It looks like a problem with the library, not your OS nor ImageMagick nor GraphicsMagick. |
After a bit of digging, it looks like we were using |
Great, hope you can get this into master soon. Thanks again! |
I got something working locally but it broke again with the example images you provided. Unfortunately, I have to take off for the night. I will take a look at getting it resolved by the end of the weekend. |
Sounds good, thanks! |
A replacement PR has been opened in #33, can you please close this PR? |
Sorry, I meant #34 |
Load ImageMagick library based on the parameter value.