mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-13 11:50:02 +01:00
Refactoring isGIF() as a utility function (#1511)
* refactor isGif * refactor isGif * fix isGif func * Update isGif.js * Update isGif.js
This commit is contained in:
committed by
Jeffrey Warren
parent
89fb3585ac
commit
1fa8c6b8c1
@@ -4,7 +4,8 @@ var defaultHtmlSequencerUi = require('./lib/defaultHtmlSequencerUi.js'),
|
|||||||
DefaultHtmlStepUi = require('./lib/defaultHtmlStepUi.js'),
|
DefaultHtmlStepUi = require('./lib/defaultHtmlStepUi.js'),
|
||||||
urlHash = require('./lib/urlHash.js'),
|
urlHash = require('./lib/urlHash.js'),
|
||||||
insertPreview = require('./lib/insertPreview.js'),
|
insertPreview = require('./lib/insertPreview.js'),
|
||||||
versionManagement = require('./lib/versionManagement.js');
|
versionManagement = require('./lib/versionManagement.js'),
|
||||||
|
isGIF = require('../src/util/isGif');
|
||||||
|
|
||||||
|
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
@@ -270,8 +271,8 @@ window.onload = function () {
|
|||||||
* @param {string} imageDataURL - The data URL for the image.
|
* @param {string} imageDataURL - The data URL for the image.
|
||||||
*/
|
*/
|
||||||
function savePDF(imageDataURL) {
|
function savePDF(imageDataURL) {
|
||||||
sequencer.getImageDimensions(imageDataURL, function(dimensions, isGIF) {
|
sequencer.getImageDimensions(imageDataURL, function(dimensions) {
|
||||||
if (!isGIF) {
|
if (isGIF(imageDataURL)) {
|
||||||
// Get the dimensions of the image.
|
// Get the dimensions of the image.
|
||||||
let pageWidth = dimensions.width;
|
let pageWidth = dimensions.width;
|
||||||
let pageHeight = dimensions.height;
|
let pageHeight = dimensions.height;
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ const intermediateHtmlStepUi = require('./intermediateHtmlStepUi.js'),
|
|||||||
urlHash = require('./urlHash.js'),
|
urlHash = require('./urlHash.js'),
|
||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
mapHtmlTypes = require('./mapHtmltypes'),
|
mapHtmlTypes = require('./mapHtmltypes'),
|
||||||
scopeQuery = require('./scopeQuery');
|
scopeQuery = require('./scopeQuery'),
|
||||||
|
isGIF = require('../../src/util/isGif');
|
||||||
|
|
||||||
function DefaultHtmlStepUi(_sequencer, options) {
|
function DefaultHtmlStepUi(_sequencer, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
@@ -379,8 +380,8 @@ function DefaultHtmlStepUi(_sequencer, options) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function updateDimensions(step){
|
function updateDimensions(step){
|
||||||
_sequencer.getImageDimensions(step.imgElement.src, function (dim, isGIF) {
|
_sequencer.getImageDimensions(step.imgElement.src, function (dim) {
|
||||||
step.ui.querySelector('.' + step.name).attributes['data-original-title'].value = `<div style="text-align: center"><p>Image Width: ${dim.width}<br>Image Height: ${dim.height}</br>${isGIF ? `Frames: ${dim.frames}` : ''}</div>`;
|
step.ui.querySelector('.' + step.name).attributes['data-original-title'].value = `<div style="text-align: center"><p>Image Width: ${dim.width}<br>Image Height: ${dim.height}</br>${isGIF(step.output) ? `Frames: ${dim.frames}` : ''}</div>`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const getPixels = require('get-pixels');
|
const getPixels = require('get-pixels');
|
||||||
module.exports = function getImageDimensions(img, cb) {
|
module.exports = function getImageDimensions(img, cb) {
|
||||||
let dimensions;
|
let dimensions;
|
||||||
let isGIF;
|
|
||||||
getPixels(img, function(err, pixels) {
|
getPixels(img, function(err, pixels) {
|
||||||
if (pixels.shape.length === 4) {
|
if (pixels.shape.length === 4) {
|
||||||
const [frames, width, height] = pixels.shape;
|
const [frames, width, height] = pixels.shape;
|
||||||
@@ -10,8 +9,6 @@ module.exports = function getImageDimensions(img, cb) {
|
|||||||
width,
|
width,
|
||||||
height
|
height
|
||||||
};
|
};
|
||||||
|
|
||||||
isGIF = true;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const [width, height] = pixels.shape;
|
const [width, height] = pixels.shape;
|
||||||
@@ -19,11 +16,9 @@ module.exports = function getImageDimensions(img, cb) {
|
|||||||
width,
|
width,
|
||||||
height
|
height
|
||||||
};
|
};
|
||||||
|
|
||||||
isGIF = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cb) cb(dimensions, isGIF);
|
if (cb) cb(dimensions);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
7
src/util/isGif.js
Normal file
7
src/util/isGif.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
module.exports = function(url){
|
||||||
|
if(url.match){
|
||||||
|
const toMatch = url.match(/data:image\/(.*);/) || 'png';
|
||||||
|
return toMatch[1] === 'gif';
|
||||||
|
}else
|
||||||
|
return false;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user