ย่อรูปผ่าน CLI บน MacOS ด้วย sips

วิธีย่อขนาดรูปและลดคุณภาพ jpeg บน macos ด้วยคำสั่ง sips ที่ติดมากับเครื่องอยู่แล้ว ไม่ต้องลงโปรแกรมเพิ่ม

sips ติดมากับ macos อยู่แล้วครับ ย่อรูปหรือแปลงไฟล์ได้เลยโดยไม่ต้องลงอะไรเพิ่ม

sips - scriptable image processing system.
This tool is used to query or modify raster image files and ColorSync ICC profiles.
Its functionality can also be used through the "Image Events" AppleScript suite.

วิธีใช้งาน

ลดคุณภาพ jpeg (ตัวอย่างคือเหลือ 70%)

sips -s formatOptions 70 input.jpg

ย่อขนาดรูปโดยคงสัดส่วนเดิม ด้านที่ยาวสุดไม่เกิน 1024px

sips -Z 1024 input.jpg

ระวังไฟล์ต้นฉบับหาย

สองคำสั่งข้างบนมันเขียนทับไฟล์เดิมเลยนะ ไม่ได้สร้างไฟล์ใหม่ให้ ลองเช็คด้วย md5 ดูได้

md5 -q photo.png
# b2f2ab5ecf28186e34c6a2aecb315a48

sips -Z 200 photo.png

md5 -q photo.png
# 8461c2903f0af97517d9442e7d83917f   <- ไฟล์เดิมโดนทับไปแล้ว

ถ้าอยากเก็บต้นฉบับไว้ให้ใส่ --out ทุกครั้งครับ

sips -Z 1024 photo.png --out photo-small.png

ดูขนาดรูปเฉย ๆ

อันนี้ไม่แตะไฟล์ ปลอดภัย

sips -g pixelWidth -g pixelHeight photo.png

Ref

  • man sips

กลับไปหน้า Blog

Copyright © 2026