Loading...
Skip to Content

AI Block Lab - Linux Server Tutorials

Linux Server Tutorials

How to Convert Images Between Popular Formats (PNG, JPG, WEBP)
How to Convert Images Between Popular Formats (PNG, JPG, WEBP)

Image format conversion is a common task for developers, designers, and system administrators. Whether you want to reduce file size, improve compatibility, or optimize images for the web, converting between formats like PNG, JPG, and WEBP is essential.

1. Understanding Image Formats

PNG (Portable Network Graphics)

  • Lossless compression
  • Supports transparency
  • Larger file sizes

JPG / JPEG (Joint Photographic Experts Group)

  • Lossy compression
  • Smaller file size
  • Best for photos

WEBP

  • Modern format by Google
  • Supports both lossy and lossless
  • Better compression than JPG/PNG

2. Converting Images Using Linux Terminal (ImageMagick)

One of the most efficient ways to convert images is using ImageMagick.

Install ImageMagick

sudo apt install imagemagick

Convert PNG to JPG

mogrify -format jpg *.png

Convert JPG to WEBP

mogrify -format webp *.jpg

Convert PNG to WEBP with quality

mogrify -format webp -quality 85 *.png

Convert using a loop (alternative method)

for file in *.png; do
    convert "$file" "${file%.png}.jpg"
done

3. Converting Images Using FFmpeg

ffmpeg is another powerful tool for image and video processing.

Install FFmpeg

sudo apt install ffmpeg

Convert PNG to JPG

ffmpeg -i input.png output.jpg

Convert JPG to WEBP

ffmpeg -i input.jpg output.webp

4. Converting Images Using Online Tools

If you prefer not to use the terminal, online tools are convenient:

  • CloudConvert
  • Convertio
  • ILoveIMG

Pros: Easy to use, no installation required.
Cons: Privacy concerns, file size limits.


5. Using Desktop Applications

GIMP

  • Open image
  • Click File → Export As
  • Select desired format (JPG, PNG, WEBP)

Photoshop

  • Use Save As or Export
  • Choose format and quality settings

6. Batch Conversion Tips

  • Always keep original files
  • Use -quality to control compression
  • Test output before массов conversion
  • Consider resizing during conversion

Example: Resize and convert

mogrify -resize 1920x1080 -format jpg *.png

7. When to Use Each Format

Format Best Use
PNG Graphics, transparency
JPG Photos, web images
WEBP Web optimization, performance

Conclusion

c For automation and server-side processing, command-line tools are the most efficient. For casual use, online tools or GUI applications may be more convenient.

Choosing the right format depends on your use case: quality, size, and compatibility all matter.

Cost: