Convert JPG to PNG Using Command Line (ImageMagick) — Windows, macOS, Linux

Convert JPG to PNG Using Command Line (ImageMagick) — Windows, macOS, Linux

Need a fast, offline way to convert images? ImageMagick lets you convert JPG/JPEG → PNG from the command line—perfect for one-off conversions, bulk folders, and automation.


Convert 1 JPG to PNG

magick input.jpg output.png


ImageMagick’s official docs use this exact “JPEG → PNG” example. 

ImageMagick


Batch convert all JPG files in a folder

magick mogrify -format png *.jpg



mogrify is ImageMagick’s batch tool; -format produces new files with the target extension. 

ImageMagick

+1


What to use (fast decision)


Use magick … when converting one file (simplest + safest). 

ImageMagick


Use magick mogrify … when converting many files (fastest for folders). 

Safety note: mogrify can overwrite originals unless output filenames differ (for example, using -format changes the output name/extension). 

Massachusetts Institute of Technology


Step 0 — Install ImageMagick (Windows + quick verification)

Windows (official installer)


ImageMagick’s official download page says the Windows version is self-installing—download the right build and run it. 

ImageMagick


Verify installation (any OS)


After installing, confirm ImageMagick runs:


magick identify -version



If this prints version info, you’re ready.


Method 1 — Convert a single JPG to PNG (most common)


Basic conversion

magick photo.jpg photo.png



This is the official “convert JPEG to PNG” pattern. 

ImageMagick


Convert + resize in one command (optional)

magick photo.jpg -resize 50% photo.png



ImageMagick’s docs show resizing before writing the PNG. 

ImageMagick


When to use resize here: when you’re preparing blog images/thumbnails and want conversion + size reduction in one step.


Method 2 — Batch convert JPG → PNG in a folder (fastest)


A) Batch convert in the same folder (creates PNG copies)

magick mogrify -format png *.jpg



The official mogrify docs show that using -format creates new output files with the target extension (the original set remains untouched in their example). 


B) Safer batch: write PNGs into an output folder


This is my recommended workflow so you never mix inputs/outputs:


macOS/Linux (Bash/Zsh)


mkdir -p out

magick mogrify -path out -format png-jpg



Windows PowerShell


New-Item -ItemType Directory -Force -Path out | Out-Null

magick mogrify -path out -format png *.jpg



Why this matters: mogrify is designed for batch transforms and can overwrite originals unless outputs differ—separating output prevents accidents. 

Massachusetts Institute of Technology


Method 3 — Convert JPG → PNG recursively (subfolders)


There are multiple ways to do recursion. Here are two reliable options.


Option A: PowerShell (Windows) — convert all JPG files under a folder


This creates PNG files next to each JPG (simple and transparent):


Get-ChildItem -Path . -Recurse -File -Filter *.jpg | ForEach-Object {

 $src = $_.FullName

 $dst = [System.IO.Path]::ChangeExtension($src, ".png")

 magick $src $dst

}


Option B: “Run mogrify in each subfolder”


If you want speed and you’re comfortable with CLI batch processing, this pattern is commonly used for “process each folder” workflows. 

Stack Overflow


Windows command-line note (important for long commands)


command-line processing docs explain that examples on their site use Linux-style line breaks with \, but:


On Linux/macOS, the line-continuation character is \


In Windows shell, use a caret ^ for line continuation 


This one detail fixes a lot of it works on the website but not on my PC issues.


Common problems (quick fixes)

“PNG didn’t improve quality”


Converting JPG → PNG doesn’t restore detail lost to JPG compression.PNG is lossless, so it’s great when you want to avoid further loss during editing/resaving—especially for text, UI, and graphics.


My PNG file is bigger


That’s normal. PNG is lossless (and may store more information). If you need smaller files for web, publish a separate guide on PNG optimization (great supporting article).


“I overwrote files”


Use one (or both) of these safety habits:


Always use -format png in batch mode so output names differ. 

Massachusetts Institute of Technology


Output into a separate folder using -path out (recommended). 

Massachusetts Institute of Technology


“Backslashes in examples break on Windows”


Replace Linux line continuation \ with Windows ^ (or put the command on one line). 

ImageMagick


Practical “recipes” (copy/paste)

Convert JPG → PNG and strip metadata (privacy-friendly)

magick input.jpg -strip output.png


Convert JPG → PNG and limit PNG size a bit (basic compression tuning)

magick input.jpg -define png:compression-level=9 output.png


(If you want, I can tailor “best compression defaults for web” based on your site niche and typical image sizes.)