Skip to content

Compress & Convert images with Gulp

Notifications You must be signed in to change notification settings

javimata/imgconverter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Requiered

Installation

> npm install

Note The latest Node version tested is 12.22.5, if use a most recent version can receive a error, if need install a old version of node can use this:

> nvm install 12.22.5
> nvm use 12.22.5

External dependencies
brew install libjpeg libpng on macOS
apt-get install -y libjpeg libpng on Ubuntu
npm install -g windows-build-tools on Windows


Using

Just put all images to convert and compress in the folder src, run the command and have all the images in the folder images.

Optional, can run just a process, this script have 2, convert and compress, if just need just one run it some like this: gulp convert or gulp compress

Important: gulp convert get the images from folder src and gulp compress get the images from the folder dest

The command gulp images is a serie for convert and compress tasks

Execute

> gulp images

This execute the basic compress for imagen in folder src, send the images converters to folder dest and the final images with compress to the folder images.

Params Default Values Description
output empty string jpeg, png, tiff and webp if is empty the output is same to original image
resize false boolean true | false If need apply a resize
width 1000 Integer Apply this width to the output image
height 1000 Integer Apply this height to the output image
fit contain cover, contain, fill, inside, outside Indicate the resize method to apply in the image
bg #ffffffff string Indicate the background for resizes using the format #rrbbggaa
q 80 Integer 0 to 100 Indicate the quality where 100 is the best but files more bigs

example

Original images Size: 932kb

Size: 3.2mb


> gulp images

Size: 495kb

Size: 1.1mb


> gulp images --resize --width 500 --height 400 --output png --fit cover

Size: 98kb 500x400px

Size: 111kb 500x400px


> gulp images --output webp

Size: 518kb

Size: 711kb

Using for a ecommerce like Shopify

Some ecommerce need images for a specific size (or optimized images), if need use this script for this can use this

> gulp images --resize --width 1000 --height 1000 --output jpg

This have a exit for all images to jpg, in a size 1000x1000px, and can put in the folder src subfolders and all images can be converter and compress

All images are from Pixabay.com