How to reduce image size of JPG file

本文介绍了一种使用 ImageMagick 工具包中的 'convert' 实用程序来压缩和调整数码相机拍摄的大尺寸 JPG 图像的方法。该脚本可以将原始图片尺寸减少到适合网络展示的大小,例如 640x480 或 1024x768 像素,同时保持图像质量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Digital camera's are being increasingly used to capture moments, screen shots, evidential photographs and other artifacts, the challenge has been the progressively large size of the JPG image files.

A large JPG image file of 3MB, 5MB, 7MB or even 15 MB has a lot of bits, that are useful for digital processing and commercial art. However, images of 640x480, 1024x768 pixel resolution are useful for consumption on the web eg. photogallery, blogs, articles etc.

'convert' is a versatile utility that is part of the ImageMagick toolkit and is available on FreeBSD, NetBSD, OpenSolaris and Linux, perhaps even on Windows.

Let us say, you have a directory full of image files with .JPG extension, that you have just moved/downloaded across from your digital camera.

Here is a sample script that does the job of reducing the size of .JPG files and renames them to filename.jpg (all lower case)

for jpgname in *.JPG;

do

filename=`basename -s .JPG ${jpgname}`;

convert -verbose -resize 640x480 +profile '*' ${jpgname} ${filename}.jpg;

done

You'd see an output like this

P1070895.JPG JPEG 2048x1536 2048x1536+0+0 8-bit DirectClass 1.231MB 0.560u 0:00.570

P1070895.jpg JPEG 2048x1536=>640x480 640x480+0+0 8-bit DirectClass 147KB 2.740u 0:01.589

P1070896.JPG JPEG 2048x1536 2048x1536+0+0 8-bit DirectClass 1.442MB 0.590u 0:00.589

P1070896.jpg JPEG 2048x1536=>640x480 640x480+0+0 8-bit DirectClass 184KB 2.780u 0:01.620

P1070897.JPG JPEG 2048x1536 2048x1536+0+0 8-bit DirectClass 1.31MB 0.570u 0:00.580

P1070897.jpg JPEG 2048x1536=>640x480 640x480+0+0 8-bit DirectClass 147KB 2.770u 0:01.620

P1070898.JPG JPEG 2048x1536 2048x1536+0+0 8-bit DirectClass 1.592MB 0.600u 0:00.599

P1070898.jpg JPEG 2048x1536=>640x480 640x480+0+0 8-bit DirectClass 197KB 2.750u 0:01.610

You're now all set to use the web ready jpg files.

the convert utility has many options, eg. reduce the size of the image by certain percentage, convert .JPG file to .PNG format etc. Please take a look at various command line options at http://www.imagemagick.org/script/command-line-options.php

转载于:https://my.oschina.net/saifi/blog/181022

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值