Skip to content

Image corruption when resizing and converting to jpg #249

@compeak

Description

@compeak

When I try to resize and convert a png to jpg sharp outputs a corrupted image.
Input:

$ pngcheck test.png 
OK: test.png (1280x877, 32-bit RGB+alpha, non-interlaced, 78.5%).
$ file test.png 
test.png: PNG image data, 1280 x 877, 8-bit/color RGBA, non-interlaced

test

convert-resize.js

var sharp = require('sharp');

var width   = 1000;
var height  = 1000;
var quality = 75;
var format  = 'jpeg';

var newImage = sharp('./test.png')
                .resize(width, height)
                .max()
                .withoutEnlargement()
                .quality(quality)
                .toFormat(format)
                .toFile('./test.jpg');

Output:

$ file test.jpg 
test.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 1000x685, frames 3

test

This seems to happen every time a png gets converted to jpg and resized to a smaller size.

vipsthumbnail test.png -o tn_%s.jpg --size 1000 produces correct output.

I used sharp 0.11.0 and vips 7.40.6 on Debian 8.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions