person github
Compressing image size can be achieved through a variety of methods and tools. Here are some common methods:
Use image editing software:
-
Adobe Photoshop:
- Open the image and select File > Save As.
- In the pop-up window, select the image format (such as JPEG, PNG, etc.).
- Adjust Quality settings to reduce file size.
-
GIMP (free) :
- Open the image and select File > Export As.
- Select image format and compression options.
-
Paint (included with Windows) :
- Open the image and select File > Save As.
- Choose a different image format, or use the "Resize" option.
Online tools:
- TinyPNG : An online PNG and JPEG image compression tool.
- Compressor.io : Supports JPEG, PNG, GIF and SVG formats.
- ImageOptim : A Mac application that also provides an online service.
Use command line tools:
- ImageMagick:
convert input.jpg -quality 85 output.jpg
- jpegoptim:
jpegoptim --max=85 input.jpg
Using a programming language:
- Python (using PIL library) :
from PIL import Image image = Image.open("input.jpg") image.save("output.jpg", quality=85)
- JavaScript (using HTML5 Canvas) :
var canvas = document.createElement("canvas"); var ctx = canvas.getContext("2d"); // ... draw image on canvas ... var compressedImage = canvas.toDataURL("image/jpeg", 0.85);
Precautions:
- Compressing images may result in reduced image quality.
- Different image formats (such as JPEG, PNG, GIF, etc.) have different compression algorithms and applicable scenarios.
Depending on your needs and available resources, you can choose the image compression method that works best for you.