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

config option to change the extension #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

odedniv
Copy link
Contributor

@odedniv odedniv commented Mar 27, 2017

In previous versions the filename remained the same across backups/reduces/resizes.

In commit f9eed2f the code was changed to change to the file type's extension, breaking my app (when I updated). I don't expect the filenames to change (even if they are wrong).

Made it optional with a config option changeExtension, that defaults to false (the original behavior). I know it's back and forth on 'breaking changes' but hopefully there are more people who haven't yet updated than there are people who have (or had to revert to the old code after finding it breaks their app).

@odedniv odedniv force-pushed the change-extension-config branch 2 times, most recently from 25f563b to 832e2a8 Compare March 27, 2017 06:29
Copy link
Owner

@ysugimoto ysugimoto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good point. But if changeExtension is false, the image converted by ImageMagick causes MIMEType mismatch and image has broken, isn't it?

To keep consistency, I think you should also stop to convert image if changeExtension is false.

bin/configtest Outdated
@@ -179,6 +179,7 @@ var reset = '\u001b[0m';
stdout.write("[Same directory]");
}
stdout.write(reset + "\r\n");
stdout.write(magenta + " Change extension: " + reset + !!changeExtension + "\r\n");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use Boolean(changeExtension)

@odedniv
Copy link
Contributor Author

odedniv commented Mar 27, 2017

Will change to Boolean(), waiting for the tests to finish because I think there's another failing test and I can't run it on my machine for some reason.

How will it bother ImageMagick? He gets the raw data (see

let img = gm(image.data).geometry(this.options.size.toString());
) he doesn't know what filename you'll save it to. All that really matters with image types is the mime type set in S3 metadata, which this project does properly. Nobody looks at the filename, only the content type received from the HTTP web server (which S3 chooses according to the metadata).

@ysugimoto
Copy link
Owner

Yes, ImageMagick doesn't have to know. ImageData.js detects MIMEType from raw data using image-type package. If we do reduce after resize, Is there the resized image's raw data like JPEG format, but raw data is PNG? I concern about this.

If this is clearly, let's merge it.

@odedniv
Copy link
Contributor Author

odedniv commented Mar 27, 2017

It should be fine, the type of the data (chosen by ImageMagick and determined by image-type) is completely unrelated to the output filename chosen, which can be anything and doesn't affect the data.

A browser downloading the image from S3 and showing it in an <img> tag would not care about the filename (URL) either, it only looks at the Content-Type header of the response which is sent by S3 according to the mime data set on the file, S3 doesn't care about the filename either.

The only problem is if someone takes the S3 file and determines the file type according to the extension (which is a bad way to determine), in this case the package's user can use the changeExtension option.

Can you check why travis is stuck? I think there might be one failing test I need to fix before this is merged.

@kdybicz
Copy link
Collaborator

kdybicz commented Mar 27, 2017

Changing you app to make it expect change of the extension would seem to be more reasonable approach for me :)

@odedniv
Copy link
Contributor Author

odedniv commented Mar 27, 2017

@kdybicz that would mean the lambda needs to update the DB (Mongo in my case). I actually have all images uploaded as "image.jpg" (to different directories) and I prefer it not to change ever 😄

@odedniv odedniv force-pushed the change-extension-config branch 2 times, most recently from d0c2794 to 1398d76 Compare March 27, 2017 21:24
@odedniv
Copy link
Contributor Author

odedniv commented Mar 28, 2017

@ysugimoto I've been wrapping my brain around these failures and I have no clue 😢

I can barely run the test suite, I have to disable eslint and then I get a lot of Error: write EPIPE. Would also be nice to be able to run a single test. Any ideas?

@ysugimoto
Copy link
Owner

ysugimoto commented Mar 29, 2017

@odedniv I saw Travis's log, some assertions are failed. And eslint error reports in your environments? An error of write EPIPE might be a process I/O error in node.js, and I'm not sure why, or when that error occurs 😢

Anyway, you can run a single test to install ava globally, I think:

$ npm install ava -g
$ ava test/e2e-jpeg.js

@ysugimoto ysugimoto closed this Mar 29, 2017
@ysugimoto ysugimoto reopened this Mar 29, 2017
@ysugimoto
Copy link
Owner

If we passed the tests, let's merge this

@odedniv
Copy link
Contributor Author

odedniv commented Mar 29, 2017

This is the output I get from running the tests:

oded@plex ~/devel/aws-lambda-image $ ava test/e2e-jpeg.js 
Reducing to: in-place
Reducing to: some
Backing up to: in-place
Resizing to: in-place
Resizing to: in-place
Resizing to: in-place
Resizing to: in-place
Resizing to: in-place
Reducing to: in-place
Reducing to: in-place
Reducing to: in-place
Reducing to: in-place
Reducing to: in-place

  1 passed
  3 exceptions

  Uncaught Exception
  Error: write EPIPE


  Uncaught Exception
  Error: write EPIPE


  ✖ Test results were not received from test/e2e-jpeg.js

It doesn't make sense on many levels... for example the file contains more than 4 tests

@ysugimoto
Copy link
Owner

Hmmmmm...
I just run test as same as you, success it.

So, I'm using node v6.9.1 on macOS. Please let me know about your environment?
In addition, please reinstall ImageMagick if you can.

@odedniv
Copy link
Contributor Author

odedniv commented Mar 30, 2017

Didn't work... Well if it succeeds for you I guess it can be merged :)

@odedniv odedniv force-pushed the change-extension-config branch from 1398d76 to 57b515e Compare April 18, 2017 16:58
@odedniv odedniv force-pushed the change-extension-config branch from 57b515e to da66ec5 Compare December 23, 2017 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants