ImageMagick Sample Code for Converting Images to @2x, @3x, @4x Sizes

Tadashi Shigeoka ·  Sat, March 16, 2019

I’ll introduce sample code for converting image files to @2x, @3x, @4x sizes using ImageMagick’s convert command.

ImageMagick

Converting Image Sizes with ImageMagick

Here’s sample code for converting image files to @2x, @3x, @4x sizes using ImageMagick’s convert command.

Please modify the image size values as needed to suit your use case.

# Environment variables to modify as needed
ORIGIN_IMAGE_NAME=sample

# Code below basically doesn't need to be changed
ORIGIN_IMAGE=$ORIGIN_IMAGE_NAME.jpg

[email protected]
[email protected]
[email protected]

convert $ORIGIN_IMAGE -resize 1376x $IMAGE_2X
convert $ORIGIN_IMAGE -resize 2064x $IMAGE_3X
convert $ORIGIN_IMAGE -resize 2752x $IMAGE_4X

# NOTE:
# For large image sizes, use lossless compression with https://tinypng.com/ etc.

That’s all from the Gemba on wanting to support @2x, @3x, @4x sizes for images with ImageMagick.

Reference Information