DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How to Batch Convert Images From PNG to JPEG

To recursively scan a directory tree for PNG images and convert them to JPEG format, you simply need to use the find Shell command and ImageMagick's convert utility.

Corey Goldberg user avatar by
Corey Goldberg
·
Feb. 06, 17 · Tutorial
Like (2)
Save
Tweet
Share
5.91K Views

Join the DZone community and get the full member experience.

Join For Free

This post briefly shows how to recursively scan a directory tree for PNG images and convert them to JPEG format. To achieve this, we use the find Shell command and ImageMagick's convert utility. Optionally, we can add GNU Parallel to speed up processing time.

First, install ImageMagick on Debian/Ubuntu with:

$ sudo apt-get install imagemagick

Once ImageMagick is installed, CD to the root of the directory tree containing your images and run:

$ find . -iname "*.png" | convert -quality 95% {} {.}.jpg

This Shell pipeline will do the following:

  • Recursively search under the current directory.

  • Match files that have the case-insensitive .png extension.

  • Convert each PNG image to JPEG format at 95% quality.

  • Save the new image with the file extension changed to .jpg.

In this version, the images were converted sequentially.  If you want to speed up processing, you can use GNU Parallel to execute the image conversions across all CPU cores.

Install GNU Parallel on Debian/Ubuntu with:

$ sudo apt-get install parallel

Once installed, simply add  parallel to the Shell pipeline before the call to convert.  This is the parallel processing version:

$ find . -iname "*.png" | parallel convert -quality 95% {} {.}.jpg

Once converted, you can delete the original PNG images with:

$ find . -iname "*.png" | parallel rm {}

And that's it! You've now batch convert your images from PNG to JPEG.

Convert (command)

Published at DZone with permission of Corey Goldberg, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Debugging Threads and Asynchronous Code
  • How To Generate Code Coverage Report Using JaCoCo-Maven Plugin
  • A Complete Guide to AngularJS Testing
  • What Should You Know About Graph Database’s Scalability?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: