Beispiel #1
0
                ImageUtil.convertToJPG('', function(err, file) {
                    assert.equal(err.code, 400);
                    assert.ok(!file);

                    // Non existing files should result in a 500
                    ImageUtil.convertToJPG('non-existing', function(err, file) {
                        assert.equal(err.code, 500);
                        assert.ok(!file);

                        return callback();
                    });
                });
Beispiel #2
0
        it('verify images get properly converted to JPG', function(callback) {
            var path = Path.resolve(__dirname + '/../../oae-preview-processor/tests/data/image.gif');
            ImageUtil.convertToJPG(path, function(err, file) {
                assert.ok(!err);
                assert.ok(file);

                // Check it has really been converted to a JPG
                gm(file.path).identify(function(err, data) {
                    assert.ok(!err);
                    assert.equal(data.format, 'JPEG');

                    // Clean up the file
                    fs.unlink(file.path, function(err) {
                        return callback();
                    });
                });
            });
        });
Beispiel #3
0
        it('verify parameter validation', function(callback) {
            ImageUtil.convertToJPG(null, function(err, file) {
                assert.equal(err.code, 400);
                assert.ok(!file);
                ImageUtil.convertToJPG('', function(err, file) {
                    assert.equal(err.code, 400);
                    assert.ok(!file);

                    // Non existing files should result in a 500
                    ImageUtil.convertToJPG('non-existing', function(err, file) {
                        assert.equal(err.code, 500);
                        assert.ok(!file);

                        return callback();
                    });
                });
            });
        });
Beispiel #4
0
var _cropThumbnail = function(ctx, path, cropMode, callback) {
    // Do a proper JPG conversion so we don't end up with `thumbnail.jpg` which are really GIFs masking as JPGs
    ImageUtil.convertToJPG(path, function(err, jpgFile) {
        if (err) {
            return callback(err);
        }

        // Crop the square thumbnail. We *always* crop a thumbnail, if the source image is too small, we'll just have to stretch it
        var opts = {
            'allowStretching': true,
            'cropMode': cropMode
        };
        _cropIntelligently(ctx, jpgFile.path, PreviewConstants.SIZES.IMAGE.THUMBNAIL, PreviewConstants.SIZES.IMAGE.THUMBNAIL, opts, 'thumbnail.jpg', function(err, thumbnailPath) {
            if (err) {
                return callback(err);
            } else if (!thumbnailPath) {
                // If we weren't able to generate the thumbnail, that means the source image is too small. There is no point in trying to render the large rectangle
                return callback();
            }

            // If the source image is smaller then the target rectangle, the path will be null
            if (thumbnailPath) {
                ctx.setThumbnail(thumbnailPath);
            }

            // Now, crop the large rectangle for activity feeds. We only create this if the source image is large enough
            opts.allowStretching = false;
            _cropIntelligently(ctx, jpgFile.path, PreviewConstants.SIZES.IMAGE.WIDE_WIDTH, PreviewConstants.SIZES.IMAGE.WIDE_HEIGHT, opts, 'wide.jpg', function(err, widePath) {
                if (err) {
                    return callback(err);
                }

                // If the source image is smaller then the target rectangle, the path will be null
                if (widePath) {
                    ctx.addPreview(widePath, 'wide');
                }
                callback();
            });
        });
    });
};
Beispiel #5
0
    ImageUtil.autoOrient(file.path, {'removeInput': true}, function(err, orientedFile) {
        if (err) {
            return cleanupOnError(err, file, callback);
        }

        // Convert it to a JPG
        ImageUtil.convertToJPG(orientedFile.path, function(err, convertedFile) {
            if (err) {
                return cleanupOnError(err, file, callback);
            }

            // Store the oriented file
            var options = {
                'resourceId': principal.id,
                'prefix': 'profilepictures',
                'filename': 'large.jpg'
            };
            ContentUtil.getStorageBackend(ctx).store(ctx, convertedFile, options, function(err, largePictureUri) {
                if (err) {
                    return cleanupOnError(err, convertedFile, callback);
                }

                // By this point the temp file has been removed from disk,
                // no need to clean up in error cases below.

                PrincipalsDAO.updatePrincipal(principal.id, {'largePictureUri': largePictureUri}, function(err) {
                    if (err) {
                        return callback(err);
                    }

                    principal.picture.largeUri = largePictureUri;
                    principal.picture.large = PrincipalsUtil.getSignedPictureUrl(ctx, largePictureUri);
                    return callback(null, principal);
                });
            });
        });
    });