Add GIF support, fixes #22.

One major change here is that thumbnails will always be generated as ".jpg".
This is potentially a breaking change, in the sense that all "png" or "jpeg" thumbnails
would be to re-calculated and re-uploaded.
pull/56/head
Romain 7 years ago
parent 38a6969eac
commit e930af7f49

@ -66,22 +66,22 @@ exports.build = function(opts) {
buildStep({
condition: opts.originalPhotos,
message: 'Photos: original',
ext: 'jpg|jpeg|png',
ext: 'jpg|jpeg|png|gif',
dest: '/original/$path/$name.$ext',
func: copyFile
}),
buildStep({
message: 'Photos: large',
ext: 'jpg|jpeg|png',
ext: 'jpg|jpeg|png|gif',
dest: '/large/$path/$name.$ext',
func: thumbs.photoLarge
}),
buildStep({
message: 'Photos: thumbnails',
ext: 'jpg|jpeg|png',
dest: '/thumbs/$path/$name.$ext',
ext: 'jpg|jpeg|png|gif',
dest: '/thumbs/$path/$name.jpg',
func: thumbs.photoSquare
}),

@ -27,7 +27,7 @@ exports.update = function(opts, callback) {
nonull: false,
nocase: true
};
glob('**/*.{jpg,jpeg,png,mp4,mov,mts,m2ts}', globOptions, callback);
glob('**/*.{jpg,jpeg,png,gif,mp4,mov,mts,m2ts}', globOptions, callback);
}
function pathAndDate(filePath, next) {

@ -1,6 +1,8 @@
var path = require('path');
var index = 0;
var GIF_REGEX = /\.gif$/i
function File(filepath, metadata) {
this.id = ++index;
this.filepath = filepath;
@ -8,6 +10,7 @@ function File(filepath, metadata) {
this.date = new Date(metadata.exif.date || metadata.fileDate);
this.caption = metadata.exif.caption;
this.isVideo = (metadata.mediaType === 'video');
this.isAnimated = GIF_REGEX.test(filepath);
this.urls = urls(filepath, metadata.mediaType);
}
@ -27,7 +30,7 @@ function videoUrls(filepath) {
function photoUrls(filepath) {
return {
thumb: 'media/thumbs/' + filepath,
thumb: 'media/thumbs/' + ext(filepath, 'jpg'),
large: 'media/large/' + filepath,
original: 'media/original/' + filepath
};

@ -12,6 +12,7 @@ exports.sizes = {
exports.photoSquare = function(task, callback) {
gm(task.src)
.autoOrient()
.coalesce()
.resize(exports.sizes.thumb, exports.sizes.thumb, '^')
.gravity('Center')
.crop(exports.sizes.thumb, exports.sizes.thumb)

@ -65,7 +65,10 @@
width="{{@root.gallery.thumbSize}}"
height="{{@root.gallery.thumbSize}}"
alt="{{filename}}" />
</a>
</a>
{{#if isAnimated}}
<img class="video-overlay" src="public/play.png" />
{{/if}}
</li>
{{~/if}}
{{~/each}}

@ -55,7 +55,10 @@
width="{{@root.gallery.thumbSize}}"
height="{{@root.gallery.thumbSize}}"
alt="{{name}}" />
</a>
</a>
{{#if isAnimated}}
<img class="video-overlay" src="public/play.png" />
{{/if}}
</li>
{{/if}}
{{/each}}

@ -73,7 +73,10 @@
width="{{@root.gallery.thumbSize}}"
height="{{@root.gallery.thumbSize}}"
alt="{{filename}}" />
</a>
</a>
{{#if isAnimated}}
<img class="video-overlay" src="public/play.png" />
{{/if}}
</li>
{{~/if}}
{{/each}}

@ -15,6 +15,29 @@ describe('File', function() {
meta.exif.date = null;
var f = new File('IMG_000001.jpg', meta);
should(f.date).eql(fixtures.date('2016-09-23'));
})
});
it('can tell if a file is a photo', function() {
var file = new File('test.jpg', fixtures.metadata());
should(file.isVideo).eql(false);
should(file.isAnimated).eql(false);
});
it('can tell if a file is a video', function() {
var meta = fixtures.metadata();
meta.mediaType = 'video';
var file = new File('test.mp4', meta);
should(file.isVideo).eql(true);
should(file.isAnimated).eql(false);
});
it('can tell if a file is an animated GIF', function() {
var meta = fixtures.metadata();
meta.mediaType = 'photo';
var file = new File('test.gif', meta);
should(file.isVideo).eql(false);
should(file.isAnimated).eql(true);
});
});

Loading…
Cancel
Save