How to Convert Image Format: JPEG to PNG, PNG to WebP (Free Tools)
Convert between image formats in seconds. JPEG, PNG, WebP, GIF - how and when to convert each.
How to Convert Image Format: JPEG to PNG, PNG to WebP (Free Tools)
Format conversion in seconds. Here's how.
Converting between formats is one of the most common image tasks. Here's everything you need to know.
Common Conversions
| From | To | When |
|---|---|---|
| JPEG | PNG | Need transparency |
| PNG | WebP | Smaller file |
| JPEG | WebP | Smaller file |
| TIFF | JPEG | For web |
Best Format Conversion Tool
Imagic AI
Best for: All conversions
- Free, unlimited
- Batch support
- Quality maintained
- Fast
JPEG to PNG
Why: Need transparency or edit further
from PIL import Image
def jpeg_to_png(input_path, output_path):
img = Image.open(input_path)
# PNG supports transparency if RGBA
# JPEG is RGB, so just convert format
if img.mode != 'RGBA':
img = img.convert('RGB')
img.save(output_path, 'PNG')
jpeg_to_png('photo.jpg', 'photo.png')
PNG to JPEG
Why: Smaller file size for photos
from PIL import Image
def png_to_jpeg(input_path, output_path, quality=85):
img = Image.open(input_path)
# PNG might have transparency
if img.mode == 'RGBA':
# Create white background
background = Image.new('RGB', img.size, (255, 255, 255))
background.paste(img, mask=img.split()[3]) # Use alpha as mask
img = background
elif img.mode != 'RGB':
img = img.convert('RGB')
img.save(output_path, 'JPEG', quality=quality)
png_to_jpeg('graphic.png', 'photo.jpg')
PNG/JPEG to WebP
Why: 30-50% smaller files
from PIL import Image
def convert_to_webp(input_path, output_path, quality=80):
img = Image.open(input_path)
# Convert to RGB if RGBA (WebP lossy)
if img.mode == 'RGBA':
img = img.convert('RGB')
img.save(output_path, 'WEBP', quality=quality)
convert_to_webp('photo.jpg', 'photo.webp')
Batch Conversion
from PIL import Image
from pathlib import Path
def batch_convert(input_dir, output_dir, output_format='WEBP', quality=80):
output_dir = Path(output_dir)
output_dir.mkdir(exist_ok=True)
extensions = ('.jpg', '.jpeg', '.png', '.bmp')
for f in Path(input_dir).glob('*'):
if f.suffix.lower() not in extensions:
continue
img = Image.open(f)
if img.mode == 'RGBA':
img = img.convert('RGB')
output_name = f.with_suffix(f'.{output_format.lower()}')
output_path = output_dir / output_name.name
if output_format == 'WEBP':
img.save(output_path, 'WEBP', quality=quality)
elif output_format == 'JPEG':
img.save(output_path, 'JPEG', quality=quality)
elif output_format == 'PNG':
img.save(output_path, 'PNG')
batch_convert('./photos', './converted', 'WEBP')
Format Decision Guide
When to Use Each Format
| Format | Best For | Compression |
|---|---|---|
| JPEG | Photos, web | Lossy, 60-90% |
| PNG | Graphics, screenshots | Lossless |
| WebP | Everything web | Both, 30-50% smaller |
| GIF | Simple animations | 256 colors |
Command Line Conversion
# ImageMagick
convert input.png output.jpg
convert input.jpg output.webp
# cwebp (WebP)
cwebp -q 80 input.png -o output.webp
# ffmpeg
ffmpeg -i input.png output.jpg
Quality Settings
JPEG
quality = 85 # Recommended: 80-90%
WebP
quality = 80 # Recommended: 75-85%
PNG
# No quality setting - always lossless
# But can optimize
optimize = True
Common Issues
Issue: Transparency Lost
Problem: Converting RGBA to JPEG
Solution: Add white background first
if img.mode == 'RGBA':
background = Image.new('RGB', img.size, (255, 255, 255))
background.paste(img, mask=img.split()[3])
img = background
Issue: Wrong Colors
Problem: CMYK vs RGB
Solution: Convert to RGB first
if img.mode == 'CMYK':
img = img.convert('RGB')
Batch Tools
Imagic AI
Supports:
- JPEG → PNG
- PNG → JPEG
- JPEG → WebP
- PNG → WebP
- Batch processing
Quick Reference
Photos → JPEG (80-85%)
Photos for web → WebP (80%)
Graphics with text → PNG
Screenshots → PNG or WebP
Everything else → WebP
FAQ
Q: Does converting formats lose quality?
A: Lossless conversion (PNG to PNG) = no loss. JPEG to PNG/WebP = some loss depending on settings.
Q: What's the smallest image format?
A: WebP for photos. SVG for graphics.
Q: Should I convert old JPEGs to WebP?
A: Yes. Can save 30-50% file size.
Q: How do I convert without losing quality?
A: Use lossless options (PNG to PNG). JPEG conversion always involves some compression.
Q: Can I convert PNG to JPEG?
A: Yes, but PNG with transparency will need white background.
My Recommendation
For conversion: Try Imagic AI
For photos: Convert to WebP
For graphics: Keep as PNG or convert to SVG
Converting image formats for 15+ years.