Images: add binary gif width detection #163

Merged
merged 2 commits into from Jan 9, 2017

Projects

None yet

3 participants

@mikesherov
Contributor

No description provided.

+ return bits.indexOf(gifHeaderHex) > -1 && bits.split(gifFrameHex).length > 2;
+ },
+
+ getDimensions: function(bits) {
@Attamusc
Attamusc Jan 9, 2017 Member

getGifDimensions maybe?

@mikesherov
mikesherov Jan 9, 2017 Contributor

I had that originally. The goal would be to do add the others should we need them, so I don't want to have to rename then...

@nemtsov

Awesome!

+ return bits.indexOf(gifHeaderHex) > -1 && bits.split(gifFrameHex).length > 2;
+ },
+
+ getDimensions: function(bits) {
@nemtsov
nemtsov Jan 9, 2017 Member

Should this method be used by dom/Image instead of its own implementation?

@mikesherov
mikesherov Jan 9, 2017 Contributor

no, dom/image assumes you have access to DOM, which has a much more robust impl than our binary inpsection.

@nemtsov
nemtsov Jan 9, 2017 Member

gotcha

+ * @throws {Error} If the src attribute is not a data-uri.
+ * @return {Boolean}
+ */
+ isCMYK: function(bits) {
@nemtsov
nemtsov Jan 9, 2017 Member

util/uploadValidator.js should use this method too, instead of Image.load() && isCMYK

@nemtsov
nemtsov Jan 9, 2017 Member
define([
  './image',
  'nbd/Promise'
], function(image, Promise) {
  'use strict';

  return {
    CMYK: function(file) {
      if (!file.readerData.isImage) {
        return Promise.resolve(file);
      }

      if (image.isCMYK(file.readerData.result)) {
        throw new Error('Your images look best on the web in RGB instead of CMYK. Please upload ' + file.readerData.name + ' as a RGB image.');
      }

      return file;
    }
  };
});
@nemtsov
nemtsov approved these changes Jan 9, 2017 View changes
@mikesherov mikesherov merged commit bf6a588 into behance:master Jan 9, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@mikesherov mikesherov deleted the mikesherov:images branch Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment