ScreenshotNeo

BlogHow-to

How to Compress Images with One Line of Code

Compress a JPEG or convert it to WebP with one command. Learn how quality settings affect output, how to check results, and how to fix common issues.

By the ScreenshotNeo team4 October 20265 min read

Use ImageMagick to compress a JPEG in one command:

magick input.jpg -quality 80 output.jpg

Replace the filenames with your paths. The output extension selects the format. The value 80 is a starting point, not a universal setting: inspect the saved image and its file size, then adjust quality for your image and use case. See the official ImageMagick conversion guide and command-line options.

1. Compress a JPEG with ImageMagick

The command reads input.jpg, applies JPEG quality 80, and writes output.jpg. Keep the input and output paths distinct while you compare results so the original remains available.

magick input.jpg -quality 80 output.jpg

ImageMagick’s JPEG quality scale runs from 1 (lowest quality and strongest compression) to 100 (best quality and least effective compression). A lower setting usually favors a smaller file at the cost of more visible degradation; the acceptable balance depends on the image and where it will appear. There is no single quality value that guarantees the smallest acceptable file for every image.

2. Convert to WebP in one command

To write WebP with ImageMagick, use a .webp output filename:

magick input.jpg -quality 80 output.webp

ImageMagick documents a WebP default quality of 75. Quality 100 or higher selects lossless mode unless explicitly overridden. See its WebP encoding options.

For a dedicated WebP command-line encoder, Google’s cwebp supports PNG, JPEG, and TIFF inputs:

cwebp -q 80 input.jpg -o output.webp

Consult Google’s cwebp documentation for its options and supported inputs.

3. Choose the output format and quality

Goal Command What to check
Keep JPEG magick input.jpg -quality 80 output.jpg Look for visible artifacts and compare file size.
Convert to WebP magick input.jpg -quality 80 output.webp Confirm the target application or browser workflow accepts WebP.
Compress PNG magick input.png -quality 80 output.png Do not assume JPEG’s quality scale applies. For PNG, ImageMagick uses the setting for zlib compression level and filter type.

The same number does not mean the same thing across formats. In particular, PNG’s -quality behavior is not a simple visual-quality slider like JPEG’s. Check the saved file rather than judging a command by its number alone. ImageMagick documents these format-specific behaviors in its option reference.

4. Make the result reproducible

  1. Keep the original file and write to a separate output path.
  2. Choose the output format based on what will consume the image.
  3. Set an initial quality value appropriate to that format.
  4. Compare the output visually at the size and context where it will be used.
  5. Check the output file size and adjust the setting if needed.

For a batch of files, run the same command on each input while giving each output a distinct name. Avoid overwriting originals until you have checked representative results and confirmed the output format is supported by your ImageMagick installation.

5. Troubleshooting

Symptom Likely cause Fix
magick: command not found or not recognized ImageMagick is not installed, or its executable is not on your PATH. Install ImageMagick for your operating system and make sure the shell can find the magick command. Installation steps vary by platform and release.
Unsupported or missing delegate / coder error The installed build cannot read the input or write the requested format. Check which formats that build supports; install or use a build with the needed format support, or choose a supported output format.
Output is larger than the input The chosen format or settings do not encode this image more compactly. Compare another suitable output format or adjust the quality setting, then inspect both appearance and size. Conversion does not guarantee a smaller file.
Image looks visibly degraded The quality setting is too aggressive for the image or display context. Raise the quality value and compare again. Use the highest compression that still meets your visual requirements.
PNG looks unchanged or the quality number seems ineffective PNG uses the setting for compression level and filter type, not JPEG-style lossy visual quality. Evaluate the resulting file size and image integrity; do not interpret the PNG value as equivalent to JPEG quality.
Command writes an unexpected format The output extension or path does not identify the intended format. Use an explicit, correct output extension such as .jpg or .webp, and check the resulting file.

6. Performance, reliability, and cost

A local command avoids sending the source image to a remote conversion service, but runtime and output size depend on the image, selected encoder, settings, and local machine. The cited documentation does not establish a universal speed or size-reduction benchmark. For repeatable workflows, preserve originals, use distinct output paths, and check outputs for representative inputs before processing a large batch.

ImageMagick is command-line software; the cited sources do not specify a price for your installation or environment. If you are processing images as part of a website screenshot workflow, ScreenshotNeo is a separate screenshot API and MCP server for developers. It captures a webpage as PNG, JPEG, WebP, or PDF; it is not an image-compression command.

Or skip the browser setup

If your goal is to capture a webpage image rather than compress an existing local image, ScreenshotNeo takes a URL in one API request. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for free.

FAQ

Does one command always make an image smaller?

No. Format and settings affect the result, and conversion can produce a larger file. Compare the actual output size.

Can I use the same quality value for JPEG and WebP?

The number is a format-specific encoder setting. Do not assume the same value produces equivalent visual quality or file size across formats.

Is this a way to compress an image already on a website?

The ImageMagick examples operate on files accessible to your local command. To capture a webpage as an image, use a browser workflow or a screenshot API such as ScreenshotNeo.