How to compress image size

person github

Compressing image size can be achieved through a variety of methods and tools. Here are some common methods:

Use image editing software:

  1. 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.
  2. GIMP (free) :

    • Open the image and select File > Export As.
    • Select image format and compression options.
  3. Paint (included with Windows) :

    • Open the image and select File > Save As.
    • Choose a different image format, or use the "Resize" option.

Online tools:

  1. TinyPNG : An online PNG and JPEG image compression tool.
  2. Compressor.io : Supports JPEG, PNG, GIF and SVG formats.
  3. ImageOptim : A Mac application that also provides an online service.

Use command line tools:

  1. ImageMagick
    convert input.jpg -quality 85 output.jpg
    
  2. jpegoptim
    jpegoptim --max=85 input.jpg
    

Using a programming language:

  1. Python (using PIL library) :
    from PIL import Image
    
    image = Image.open("input.jpg")
    image.save("output.jpg", quality=85)
    
  2. 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.

Guess you like

Origin blog.csdn.net/m0_57236802/article/details/132925243