#1126·uCrop

How does sharp infer the height if the width is provided?

Author: CominovacodeCreated May 25, 2026Updated May 25, 2026

What are you trying to achieve? I am writing a webpack loader to optimize images, some of that work includes resizing. For dev purposes I need to know up-front what will be the image dimensions. As the user can specify the width only I need to infer the height. After looking at sharp source code I found these lines: