Linux/Bilder/optimieren: Unterschied zwischen den Versionen

Aus Foxwiki
Änderung 11237 von Dirkwagner (Diskussion) rückgängig gemacht.
Markierung: Rückgängigmachung
Keine Bearbeitungszusammenfassung
 
(31 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
= Optimize Images  =
* You have a lot of images, and want to optimize and compress the images without losing its original quality before uploading them to any cloud or local storages?  
 
* There are plenty of GUI applications available which will help you to optimize the images.  
= JPEG and PNG  =
* However, here are two simple command line utilities to optimize images and they are:
 
# jpegoptim – is a utility to optimize/compress JPEG files without loosing quality.  
You have a lot of images, and want to optimize and compress the images without losing its original quality before uploading them to any cloud or local storages? There are plenty of GUI applications available which will help you to optimize the images. However, here are two simple command line utilities to optimize images and they are:# '''jpegoptim''' – is a utility to optimize/compress JPEG files without loosing quality.  
# OptiPNG – is a small program that optimize PNG images to smaller size without losing any information. Compress and Optimize JPEG and PNG Images in Linux
# '''OptiPNG''' – is a small program that optimize PNG images to smaller size without losing any information.  
 
 
 
Compress and Optimize JPEG and PNG Images in Linux


Using these two tools, you can either optimize a single or multiple images at a time.
Using these two tools, you can either optimize a single or multiple images at a time.


=== Compress or Optimize JPEG Images from Command Line ===
== Compress or Optimize JPEG Images from Command Line ==


'''jpegoptim''' is a command line tool that can be used to optimize and compress JPEG, JPG and JFIF files without losing its actual quality. This tool supports lossless optimization, which is based on optimizing the Huffman tables.
=== jpegoptim ===
* is a command line tool that can be used to optimize and compress JPEG, JPG and JFIF files without losing its actual quality.  
* This tool supports lossless optimization, which is based on optimizing the Huffman tables.


==== Install jpegoptim in Linux ====
==== Install jpegoptim in Linux ====
 
# apt install jpegoptim
To install '''jpegoptim''' on your Linux systems, run the following command from your terminal.
 
===== On Debian and it’s Derivatives =====
 
<nowiki># apt-get install jpegoptim</nowiki>
or
$ sudo apt-get install jpegoptim
 
===== On RedHat based Systems =====
 
On RPM based systems like '''RHEL''', '''CentOS''', '''Fedora''' etc., you need to [https://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/ install and enable EPEL repository] or alternatively, you can install the epel repository directly from the commandline as shown:
 
<nowiki># yum install epel-release</nowiki>
<nowiki># dnf install epel-release </nowiki>  [On '''Fedora 22+''' versions]
 
Next install jpegoptim program from the repository as shown:
 
<nowiki># yum install jpegoptim</nowiki>
<nowiki># dnf install jpegoptim </nowiki>  [On '''Fedora 22+''' versions]


==== How to Use Jpegoptim Image Optimizer ====
==== How to Use Jpegoptim Image Optimizer ====
The syntax of jpegoptm is:
The syntax of jpegoptm is:
$ jpegoptim filename.jpeg
$ jpegoptim [options] filename.jpeg


$ jpegoptim filename.jpeg
Let’s now compress the following tecmint.jpeg image, but before optimizing the image, first find out the actual size of the image using [[du]] as shown.
$ jpegoptim [options] filename.jpeg
$ du -sh tecmint.jpeg  
 
6.2M    tecmint.jpeg
Let’s now compress the following <tt>tecmint.jpeg</tt> image, but before optimizing the image, first find out the actual size of the image using [https://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/ du command] as shown.
 
$ du -sh tecmint.jpeg  
 
<span style="color:#ffff00;">'''6.2M    tecmint.jpeg'''</span>
 
Here the actual file size is '''6.2MB''', now compress this file by running:


$ jpegoptim tecmint.jpeg  
Here the actual file size is 6.2MB, now compress this file by running:
$ jpegoptim tecmint.jpeg


Optimize JPEG Image in Linux
== Optimize JPEG Image in Linux ==
* Open the compressed image in any image viewer application, you will not find any major differences.
* The source and compressed images will have the same quality.
* The above command optimizes the images to the maximum possible size.
* However, you can compress the given image to a specific size to, but it disables the lossless optimization.


Open the compressed image in any image viewer application, you will not find any major differences. The source and compressed images will have the same quality.
For example, let us compress above the image from 5.6MB to around 250k.
 
$ jpegoptim --size=250k tecmint.jpeg
The above command optimizes the images to the maximum possible size. However, you can compress the given image to a specific size to, but it disables the lossless optimization.
 
For example, let us compress above the image from '''5.6MB''' to around '''250k'''.
 
$ jpegoptim --size=250k tecmint.jpeg
 
Optimize Image Fix Size


=== Optimize Image Fix Size ===
==== Batch JPEG Image Compression and Optimization ====
==== Batch JPEG Image Compression and Optimization ====
* You might ask how to compress the images in the entire directory, that’s not difficult too.
* Go to the directory where you have the images.


You might ask how to compress the images in the entire directory, that’s not difficult too. Go to the directory where you have the images.
$ cd img/
 
/img $ ls -l
<span style="color:#ffff00;">'''tecmint@tecmint ~ $ cd img/'''</span>
total 65184
<span style="color:#ffff00;">'''tecmint@tecmint ~/img $ ls -l'''</span>
-rwxr----- 1 tecmint tecmint 6680532 Jan 19 12:21 DSC_0310.JPG
total 65184
-rwxr----- 1 tecmint tecmint 6846248 Jan 19 12:21 DSC_0311.JPG
-rwxr----- 1 tecmint tecmint 6680532 Jan 19 12:21 DSC_0310.JPG
-rwxr----- 1 tecmint tecmint 7174430 Jan 19 12:21 DSC_0312.JPG
-rwxr----- 1 tecmint tecmint 6846248 Jan 19 12:21 DSC_0311.JPG
-rwxr----- 1 tecmint tecmint 6514309 Jan 19 12:21 DSC_0313.JPG
-rwxr----- 1 tecmint tecmint 7174430 Jan 19 12:21 DSC_0312.JPG
-rwxr----- 1 tecmint tecmint 6755589 Jan 19 12:21 DSC_0314.JPG
-rwxr----- 1 tecmint tecmint 6514309 Jan 19 12:21 DSC_0313.JPG
-rwxr----- 1 tecmint tecmint 6789763 Jan 19 12:21 DSC_0315.JPG
-rwxr----- 1 tecmint tecmint 6755589 Jan 19 12:21 DSC_0314.JPG
-rwxr----- 1 tecmint tecmint 6958387 Jan 19 12:21 DSC_0316.JPG
-rwxr----- 1 tecmint tecmint 6789763 Jan 19 12:21 DSC_0315.JPG
-rwxr----- 1 tecmint tecmint 6463855 Jan 19 12:21 DSC_0317.JPG
-rwxr----- 1 tecmint tecmint 6958387 Jan 19 12:21 DSC_0316.JPG
-rwxr----- 1 tecmint tecmint 6614855 Jan 19 12:21 DSC_0318.JPG
-rwxr----- 1 tecmint tecmint 6463855 Jan 19 12:21 DSC_0317.JPG
-rwxr----- 1 tecmint tecmint 5931738 Jan 19 12:21 DSC_0319.JPG
-rwxr----- 1 tecmint tecmint 6614855 Jan 19 12:21 DSC_0318.JPG
-rwxr----- 1 tecmint tecmint 5931738 Jan 19 12:21 DSC_0319.JPG


And then run the following command to compress all images at once.
And then run the following command to compress all images at once.


<span style="color:#ffff00;">'''tecmint@tecmint ~/img $ jpegoptim *.JPG'''</span>
$ jpegoptim *.JPG
DSC_0310.JPG 6000x4000 24bit N Exif  [OK] 6680532 --> 5987094 bytes (10.38%), optimized.
DSC_0310.JPG 6000x4000 24bit N Exif  [OK] 6680532 --> 5987094 bytes (10.38%), optimized.
DSC_0311.JPG 6000x4000 24bit N Exif  [OK] 6846248 --> 6167842 bytes (9.91%), optimized.
DSC_0311.JPG 6000x4000 24bit N Exif  [OK] 6846248 --> 6167842 bytes (9.91%), optimized.
DSC_0312.JPG 6000x4000 24bit N Exif  [OK] 7174430 --> 6536500 bytes (8.89%), optimized.
DSC_0312.JPG 6000x4000 24bit N Exif  [OK] 7174430 --> 6536500 bytes (8.89%), optimized.
DSC_0313.JPG 6000x4000 24bit N Exif  [OK] 6514309 --> 5909840 bytes (9.28%), optimized.
DSC_0313.JPG 6000x4000 24bit N Exif  [OK] 6514309 --> 5909840 bytes (9.28%), optimized.
DSC_0314.JPG 6000x4000 24bit N Exif  [OK] 6755589 --> 6144165 bytes (9.05%), optimized.
DSC_0314.JPG 6000x4000 24bit N Exif  [OK] 6755589 --> 6144165 bytes (9.05%), optimized.
DSC_0315.JPG 6000x4000 24bit N Exif  [OK] 6789763 --> 6090645 bytes (10.30%), optimized.
DSC_0315.JPG 6000x4000 24bit N Exif  [OK] 6789763 --> 6090645 bytes (10.30%), optimized.
DSC_0316.JPG 6000x4000 24bit N Exif  [OK] 6958387 --> 6354320 bytes (8.68%), optimized.
DSC_0316.JPG 6000x4000 24bit N Exif  [OK] 6958387 --> 6354320 bytes (8.68%), optimized.
DSC_0317.JPG 6000x4000 24bit N Exif  [OK] 6463855 --> 5909298 bytes (8.58%), optimized.
DSC_0317.JPG 6000x4000 24bit N Exif  [OK] 6463855 --> 5909298 bytes (8.58%), optimized.
DSC_0318.JPG 6000x4000 24bit N Exif  [OK] 6614855 --> 6016006 bytes (9.05%), optimized.
DSC_0318.JPG 6000x4000 24bit N Exif  [OK] 6614855 --> 6016006 bytes (9.05%), optimized.
DSC_0319.JPG 6000x4000 24bit N Exif  [OK] 5931738 --> 5337023 bytes (10.03%), optimized.
DSC_0319.JPG 6000x4000 24bit N Exif  [OK] 5931738 --> 5337023 bytes (10.03%), optimized.


You can also compress multiple selected images at once:
You can also compress multiple selected images at once:


<span style="color:#ffff00;">'''$ jpegoptim DSC_0310.JPG DSC_0311.JPG DSC_0312.JPG '''</span>
$ jpegoptim DSC_0310.JPG DSC_0311.JPG DSC_0312.JPG  
DSC_0310.JPG 6000x4000 24bit N Exif  [OK] 6680532 --> 5987094 bytes (10.38%), optimized.
DSC_0310.JPG 6000x4000 24bit N Exif  [OK] 6680532 --> 5987094 bytes (10.38%), optimized.
DSC_0311.JPG 6000x4000 24bit N Exif  [OK] 6846248 --> 6167842 bytes (9.91%), optimized.
DSC_0311.JPG 6000x4000 24bit N Exif  [OK] 6846248 --> 6167842 bytes (9.91%), optimized.
DSC_0312.JPG 6000x4000 24bit N Exif  [OK] 7174430 --> 6536500 bytes (8.89%), optimized.
DSC_0312.JPG 6000x4000 24bit N Exif  [OK] 7174430 --> 6536500 bytes (8.89%), optimized.
 
For more details about '''jpegoptim''' tool, check out the man pages.


$ man jpegoptim  
For more details about jpegoptim tool, check out the man pages.
$ man jpegoptim  


=== Compress or Optimize PNG Images from Command Line ===
=== Compress or Optimize PNG Images from Command Line ===
 
* OptiPNG is a command line tool used to optimize and compress PNG (portable network graphics) files without losing its original quality.
'''OptiPNG''' is a command line tool used to optimize and compress PNG (portable network graphics) files without losing its original quality.
* The installation and usage of OptiPNG is very similar to jpegoptim.
 
The installation and usage of '''OptiPNG''' is very similar to '''jpegoptim'''.


==== Install OptiPNG in Linux ====
==== Install OptiPNG in Linux ====
 
# apt-get install optipng
To install '''OptiPNG''' on your Linux systems, run the following command from your terminal.
 
===== On Debian and it’s Derivatives =====
 
<nowiki># apt-get install optipng</nowiki>
or
$ sudo apt-get install optipng
 
===== On RedHat based Systems =====
 
<nowiki># yum install optipng</nowiki>
<nowiki># dnf install optipng </nowiki>  [On Fedora '''22+''' versions]
 
<span style="color:#ff0000;">'''Note'''</span>: You must have '''epel repository''' enabled on your '''RHEL/CentOS''' based systems to install '''optipng''' program.


==== How to Use OptiPNG Image Optimizer ====
==== How to Use OptiPNG Image Optimizer ====
The general syntax of optipng is:
$ optipng filename.png
$ optipng [options] filename.png


The general syntax of '''optipng''' is:
Let us compress the tecmint.png image, but before optimizing, first check the actual size of the image as shown:
 
  $ ls -lh tecmint.png</span>  
$ optipng filename.png
-rw------- 1 tecmint tecmint 350K Jan 19 12:54 tecmint.png
$ optipng [options] filename.png
 
Let us compress the <tt>tecmint.png</tt> image, but before optimizing, first check the actual size of the image as shown:
 
<span style="color:#ffff00;">'''tecmint@tecmint ~/img $ ls -lh tecmint.png'''</span>  
-rw------- 1 tecmint tecmint '''350K''' Jan 19 12:54 tecmint.png


Here the actual file size of above image is '''350K''', now compress this file by running:
Here the actual file size of above image is 350K, now compress this file by running:
 
$ optipng tecmint.png
<span style="color:#ffff00;">'''tecmint@tecmint ~/img $ optipng tecmint.png'''</span>
OptiPNG 0.6.4: Advanced PNG optimizer.
OptiPNG 0.6.4: Advanced PNG optimizer.
Copyright (C) 2001-2010 Cosmin Truta.
Copyright (C) 2001-2010 Cosmin Truta.
** Processing: tecmint.png
 
1493x914 pixels, 4x8 bits/pixel, RGB+alpha
<nowiki>** Processing: tecmint.png</nowiki>
Reducing image to 3x8 bits/pixel, RGB
1493x914 pixels, 4x8 bits/pixel, RGB+alpha
Input IDAT size = 357525 bytes
Reducing image to 3x8 bits/pixel, RGB
Input file size = 358098 bytes
Input IDAT size = 357525 bytes
Trying:
Input file size = 358098 bytes
 
Trying:
   zc = 9  zm = 8  zs = 0  f = 0        IDAT size = 249211
   zc = 9  zm = 8  zs = 0  f = 0        IDAT size = 249211
 
Selecting parameters:
Selecting parameters:
   zc = 9  zm = 8  zs = 0  f = 0        IDAT size = 249211
   zc = 9  zm = 8  zs = 0  f = 0        IDAT size = 249211
Output IDAT size = 249211 bytes (108314 bytes decrease)
Output file size = 249268 bytes (108830 bytes = 30.39% decrease)


Output IDAT size = 249211 bytes (108314 bytes decrease)
* As you see in the above output, the size of the tecmint.png file has been reduced up to 30.39%.
Output file size = 249268 bytes (108830 bytes = 30.39% decrease)
* Now verify the file size again using:
 
$ ls -lh tecmint.png  
As you see in the above output, the size of the '''tecmint.png''' file has been reduced up to '''30.39%'''. Now verify the file size again using:
-rw-r--r-- 1 tecmint tecmint 244K Jan 19 12:56 tecmint.png
 
<span style="color:#ffff00;">'''tecmint@tecmint ~/img $ ls -lh tecmint.png '''</span>
-rw-r--r-- 1 tecmint tecmint '''244K''' Jan 19 12:56 tecmint.png


Open the compressed image in any image viewer application, you will not find any major differences between the original and compressed files. The source and compressed images will have the same quality.
Open the compressed image in any image viewer application, you will not find any major differences between the original and compressed files. The source and compressed images will have the same quality.


==== Batch PNG Image Compression and Optimization ====
==== Batch PNG Image Compression and Optimization ====
To compress batch or multiple PNG images at once, just go the directory where all images resides and run the following command to compress.
To compress batch or multiple PNG images at once, just go the directory where all images resides and run the following command to compress.
 
$ cd img/
<span style="color:#ffff00;">'''tecmint@tecmint ~ $ cd img/'''</span>
$ optipng *.png
<span style="color:#ffff00;">'''tecmint@tecmint ~/img $ optipng *.png'''</span>


OptiPNG 0.6.4: Advanced PNG optimizer.
OptiPNG 0.6.4: Advanced PNG optimizer.
Copyright (C) 2001-2010 Cosmin Truta.
Copyright (C) 2001-2010 Cosmin Truta.
 
** Processing: Debian-8.png
<nowiki>** Processing: Debian-8.png</nowiki>
720x345 pixels, 3x8 bits/pixel, RGB
720x345 pixels, 3x8 bits/pixel, RGB
Input IDAT size = 95151 bytes
Input IDAT size = 95151 bytes
Input file size = 95429 bytes
Input file size = 95429 bytes
Trying:
 
Trying:
   zc = 9  zm = 8  zs = 0  f = 0        IDAT size = 81388
   zc = 9  zm = 8  zs = 0  f = 0        IDAT size = 81388
 
Selecting parameters:
Selecting parameters:
   zc = 9  zm = 8  zs = 0  f = 0        IDAT size = 81388
   zc = 9  zm = 8  zs = 0  f = 0        IDAT size = 81388
 
Output IDAT size = 81388 bytes (13763 bytes decrease)
Output IDAT size = 81388 bytes (13763 bytes decrease)
Output file size = 81642 bytes (13787 bytes = 14.45% decrease)
Output file size = 81642 bytes (13787 bytes = 14.45% decrease)
 
** Processing: Fedora-22.png
<nowiki>** Processing: Fedora-22.png</nowiki>
720x345 pixels, 4x8 bits/pixel, RGB+alpha
720x345 pixels, 4x8 bits/pixel, RGB+alpha
Reducing image to 3x8 bits/pixel, RGB
Reducing image to 3x8 bits/pixel, RGB
Input IDAT size = 259678 bytes
Input IDAT size = 259678 bytes
Input file size = 260053 bytes
Input file size = 260053 bytes
 
Trying:
Trying:
   zc = 9  zm = 8  zs = 0  f = 5        IDAT size = 222479
   zc = 9  zm = 8  zs = 0  f = 5        IDAT size = 222479
   zc = 9  zm = 8  zs = 1  f = 5        IDAT size = 220311
   zc = 9  zm = 8  zs = 1  f = 5        IDAT size = 220311
   zc = 1  zm = 8  zs = 2  f = 5        IDAT size = 216744
   zc = 1  zm = 8  zs = 2  f = 5        IDAT size = 216744
 
Selecting parameters:
Selecting parameters:
   zc = 1  zm = 8  zs = 2  f = 5        IDAT size = 216744
   zc = 1  zm = 8  zs = 2  f = 5        IDAT size = 216744
Output IDAT size = 216744 bytes (42934 bytes decrease)
Output file size = 217035 bytes (43018 bytes = 16.54% decrease)
....


Output IDAT size = 216744 bytes (42934 bytes decrease)
For more details about optipng check man pages.
Output file size = 217035 bytes (43018 bytes = 16.54% decrease)
$ man optipng
....
 
For more details about '''optipng''' check man pages.
 
$ man optipng


== Quellen ==
== Quellen ==
# https://www.tecmint.com/optimize-and-compress-jpeg-or-png-batch-images-linux-commandline/
# https://www.tecmint.com/optimize-and-compress-jpeg-or-png-batch-images-linux-commandline/


= Optimize and Compress PNG Files In Bulk =
= Optimize and Compress PNG Files In Bulk =
 
I have lots of images in png format (over 250k+ png). Properly formatting and compressing png images can save many bytes of data. How do I compress and optimize png images on my amazon cloud account so that I can save bandwidth on cloudfront cdn account? How do I use an image compressor to create lossless compression on PNG files, with no effect on image quality in bulk using Red Hat Enterprise Linux bash shell?The following image format is recommended and used by big web sites such as Google / Yahoo / Amazon / Facebook etc:\n\n# PNG file format is recommended for web.  
 
# GIF file format is recommended for small size images.  
 
# JPG file format is recommended for high resolution photographic-style images.  
I have lots of images in png format (over 250k+ png). Properly formatting and compressing png images can save many bytes of data. How do I compress and optimize png images on my amazon cloud account so that I can save bandwidth on cloudfront cdn account? How do I use an image compressor to create lossless compression on PNG files, with no effect on image quality in bulk using Red Hat Enterprise Linux bash shell?The following image format is recommended and used by big web sites such as Google / Yahoo / Amazon / Facebook etc:
# Do not use BMPs or TIFFs. \n\n
 
 
# PNG file format is recommended for '''web'''.  
# GIF file format is recommended for''' small size''' images.  
# JPG file format is recommended for '''high resolution photographic-style''' images.  
# '''Do not use''' BMPs or TIFFs.  
 
 


== Say hello to optipng ==
== Say hello to optipng ==
 
* You need to use a tool called optipng.  
You need to use a tool called optipng. It is a PNG optimizer that recompresses image files to a smaller size, without losing any information. This program also converts external formats (BMP, GIF, PNM and TIFF) to optimized PNG, and performs PNG integrity checks and corrections. This tool can be installed on any server powered by Unix or Linux operating systems.
* It is a PNG optimizer that recompresses image files to a smaller size, without losing any information.  
* This program also converts external formats (BMP, GIF, PNM and TIFF) to optimized PNG, and performs PNG integrity checks and corrections.  
* This tool can be installed on any server powered by Unix or Linux operating systems.


=== Installation ===
=== Installation ===
 
  $ sudo apt-get install optipng  
First, turn on [https://www.cyberciti.biz/faq/fedora-sl-centos-redhat6-enable-epel-repo/ EPEL repo] and type the following [https://www.cyberciti.biz/faq/rhel-centos-fedora-linux-yum-command-howto/ yum command to install optipng]:<tt><nowiki>## ** first enable epel repo on centos 7 ** ##</nowiki><nowiki># yum install epel-release</nowiki><nowiki># yum install optipng</nowiki></tt>Sample outputs:
 
Loaded plugins: auto-update-debuginfo, protectbase, rhnplugin
 
0 packages excluded due to repository protections
 
Setting up Install Process
 
Resolving Dependencies
 
--> Running transaction check
 
---> Package optipng.x86_64 0:0.6.4-1.el6 will be installed
 
--> Finished Dependency Resolution
 
&nbsp;
 
Dependencies Resolved
 
&nbsp;
 
<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;"><nowiki>==============================================================================</nowiki></span>
 
Package          Arch            Version              Repository      Size
 
<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;"><nowiki>==============================================================================</nowiki></span>
 
Installing:
 
  optipng          x86_64          0.6.4-1.el6          epel            82 k
&nbsp;
 
Transaction Summary
 
<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;"><nowiki>==============================================================================</nowiki></span>
 
Install 1 Package(s)
 
&nbsp;
 
Total download size: 82 k
 
Installed size: 181 k
 
Is this ok <span style="color:#000066;">'''[y/N]'''</span>: y
 
Downloading Packages:
 
optipng-0.6.4-1.el6.x86_64.rpm | 82 kB 00:00
 
Running rpm_check_debug
 
Running Transaction Test
 
Transaction Test Succeeded
 
Running Transaction
 
  Installing : optipng-0.6.4-1.el6.x86_64                                  1/1
  Verifying  : optipng-0.6.4-1.el6.x86_64                                  1/1
&nbsp;
 
Installed:
 
  optipng.x86_64 0:0.6.4-1.el6                                               
&nbsp;
 
Complete!
 
Debian and Ubuntu/Mint Linux user type the following [https://www.cyberciti.biz/tips/linux-debian-package-management-cheat-sheet.html apt-get command] to install the same:<tt>$ sudo apt-get install optipng</tt>
 
Reading package lists... Done
Building dependency tree     
Reading state information... Done
The following NEW packages will be installed:
  optipng
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 89.0 kB of archives.
After this operation, 212 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main optipng amd64 0.6.4-1build1 [89.0 kB]
Fetched 89.0 kB in 0s (419 kB/s) 
Selecting previously unselected package optipng.
(Reading database ... 16090 files and directories currently installed.)
Preparing to unpack .../optipng_0.6.4-1build1_amd64.deb ...
Unpacking optipng (0.6.4-1build1) ...
Setting up optipng (0.6.4-1build1) ...


== How do I use optipng command? ==
== How do I use optipng command? ==
The syntax is:
The syntax is:
optipng file


optipng <span style="color:#7a0874;">[</span>options<span style="color:#7a0874;">]</span> <span style="color:#c20cb9;">file</span>


{| style="border-spacing:0;width:6.036cm;"
optipng <span style="color:#7a0874;">[</span>options<span style="color:#7a0874;">]</span> input.png
|- style="border:none;padding:0.049cm;"
|| optipng <span style="color:#c20cb9;">'''file'''</span>
 
optipng <span style="color:#7a0874;">'''['''</span>options<span style="color:#7a0874;">''']'''</span> <span style="color:#c20cb9;">'''file'''</span>
 
optipng <span style="color:#7a0874;">'''['''</span>options<span style="color:#7a0874;">''']'''</span> input.png
|-
|-
|}
|}
Zeile 353: Zeile 191:
test.png (tiffinfo compatible labels)...
test.png (tiffinfo compatible labels)...
   Image Width: 1164 Image Length: 911
   Image Width: 1164 Image Length: 911
   Bits/Sample: 8
   Bit/Sample: 8
   Samples/Pixel: 3
   Samples/Pixel: 3
   Pixel Depth: 24
   Pixel Depth: 24
Zeile 376: Zeile 214:
Copyright (C) 2001-2010 Cosmin Truta.
Copyright (C) 2001-2010 Cosmin Truta.


&nbsp;


<nowiki>** Processing: test.png</nowiki>
<nowiki>** Processing: test.png</nowiki>
Zeile 382: Zeile 220:
1164x911 pixels, 3x8 bits/pixel, RGB
1164x911 pixels, 3x8 bits/pixel, RGB


Input IDAT size <span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;"> 284778 bytes</span>
Input IDAT size <span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;"> 284778 bytes</span>


Input file size <span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;"> 285286 bytes</span>
Input file size <span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;"> 285286 bytes</span>


&nbsp;


Trying:
Trying:


   <span style="color:#000099;">zc</span> <span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;"> 9  zm = 8  zs = 0  f = 0        IDAT size = 215274</span>
   <span style="color:#000099;">zc</span> <span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;"> 9  zm = 8  zs = 0  f = 0        IDAT size = 215274</span>
&nbsp;


Selecting parameters:
Selecting parameters:


   <span style="color:#000099;">zc</span> <span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;"> 9  zm = 8  zs = 0  f = 0        IDAT size = 215274</span>
   <span style="color:#000099;">zc</span> <span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;"> 9  zm = 8  zs = 0  f = 0        IDAT size = 215274</span>
&nbsp;
 
Output IDAT size <span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;"> 215274 bytes (69504 bytes decrease)</span>
 
Output file size <span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;"> 215374 bytes (69912 bytes </span><span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;"> 24.51% decrease)</span>
 
File size is reduced by 24.51%:<tt>$ ls -lh test.png</tt>Sample outputs:<tt>-rw-r--r-- 1 vivek vivek 211K Nov 29 02:40 test.png</tt>You can verify the quality of both images (click to enlarge):


Output IDAT size <span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;"> 215274 bytes (69504 bytes decrease)</span>


Output file size <span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;"> 215374 bytes (69912 bytes </span><span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;"> 24.51% decrease)</span>


File size is reduced by 24.51%:<tt>$ ls -lh test.png</tt>Sample outputs:<tt>-rw-r--r-- 1 vivek vivek 211K Nov 29 02:40 test.png</tt>You can verify the quality of both images (click to enlarge):\n\n


Optimized test.png file ensures that it loads faster for users on slow connections. It will also save 24.51% bytes per image view in terms of both network bandwidth and storage. According to Google:
Optimized test.png file ensures that it loads faster for users on slow connections. It will also save 24.51% bytes per image view in terms of both network bandwidth and storage. According to Google:
Zeile 413: Zeile 248:
== How do I optimize files in bulk? ==
== How do I optimize files in bulk? ==


Use [https://www.cyberciti.biz/faq/bash-for-loop/ a bash for loop as follows]:
Use [https://www.cyberciti.biz/faq/bash-for-loop/ a bash for loop as follows]:\n\n{| style="border-spacing:0;width:20.652cm;"
 
 
{| style="border-spacing:0;width:20.652cm;"
|- style="border:none;padding:0.049cm;"
|- style="border:none;padding:0.049cm;"
|| <div style="color:#666666;">''<nowiki>#!/bin/bash</nowiki>''</div>
|| <div style="color:#666666;">''<nowiki>#!/bin/bash</nowiki>''</div>


<span style="color:#7a0874;">'''cd'''</span> <span style="color:#000000;">'''/'''</span>path<span style="color:#000000;">'''/'''</span>to<span style="color:#000000;">'''/'''</span>png<span style="color:#000000;">'''/'''</span>storage<span style="color:#000000;">'''/'''</span><span style="color:#000000;">2010</span><span style="color:#000000;">'''/'''</span>01<span style="color:#000000;">'''/'''</span>c<span style="color:#000000;">'''/'''</span>
<span style="color:#7a0874;">cd</span> <span style="color:#000000;">/</span>path<span style="color:#000000;">/</span>to<span style="color:#000000;">/</span>png<span style="color:#000000;">/</span>storage<span style="color:#000000;">/</span><span style="color:#000000;">2010</span><span style="color:#000000;">/</span>01<span style="color:#000000;">/</span>c<span style="color:#000000;">/</span>


<span style="color:#c20cb9;">'''mkdir'''</span> optimized  
<span style="color:#c20cb9;">mkdir</span> optimized  


<div style="color:#666666;">''<nowiki>## store optimized images in optimized directory ##</nowiki>''</div>
<div style="color:#666666;">''<nowiki>## store optimized images in optimized directory ##</nowiki>''</div>
Zeile 428: Zeile 260:
<div style="color:#666666;">''<nowiki>## Keep file system permission and make a backup of original PNG (see options below) </nowiki><nowiki>##</nowiki>''</div>
<div style="color:#666666;">''<nowiki>## Keep file system permission and make a backup of original PNG (see options below) </nowiki><nowiki>##</nowiki>''</div>


<span style="color:#000000;">'''for'''</span> i <span style="color:#000000;">'''in'''</span> <span style="color:#000000;">'''<nowiki>*</nowiki>'''</span>.png; <span style="color:#000000;">'''do'''</span> optipng <span style="color:#660033;">-o5</span> <span style="color:#660033;">-quiet</span> <span style="color:#660033;">-keep</span> <span style="color:#660033;">-preserve</span> <span style="color:#660033;">-dir</span> optimized <span style="color:#660033;">-log</span> optipng.log <span style="color:#ff0000;">"</span><span style="color:#007800;">$i</span><span style="color:#ff0000;">"</span><nowiki>; </nowiki><span style="color:#000000;">'''done'''</span>
<span style="color:#000000;">for</span> i <span style="color:#000000;">in</span> <span style="color:#000000;"><nowiki>*</nowiki></span>.png; <span style="color:#000000;">do</span> optipng <span style="color:#660033;">-o5</span> <span style="color:#660033;">-quiet</span> <span style="color:#660033;">-keep</span> <span style="color:#660033;">-preserve</span> <span style="color:#660033;">-dir</span> optimized <span style="color:#660033;">-log</span> optipng.log <span style="color:#ff0000;">"</span><span style="color:#007800;">$i</span><span style="color:#ff0000;">"</span><nowiki>; </nowiki><span style="color:#000000;">done</span>
|-
|-
|}
|}
You need to make changes to your code. For example, url path to optimize url will be as follows:<tt>http://s0.cyberciti.org/foo/bar/optimized/test.png</tt>Alternatively, you can overwrite existing PNG images:
You need to make changes to your code. For example, url path to optimize url will be as follows:<tt>http://s0.cyberciti.org/foo/bar/optimized/test.png</tt>Alternatively, you can overwrite existing PNG images:\n\n{| style="border-spacing:0;width:18.958cm;"
 
 
{| style="border-spacing:0;width:18.958cm;"
|- style="border:none;padding:0.049cm;"
|- style="border:none;padding:0.049cm;"
|| <div style="color:#666666;">''<nowiki>#!/bin/bash</nowiki>''</div>
|| <div style="color:#666666;">''<nowiki>#!/bin/bash</nowiki>''</div>


<span style="color:#7a0874;">'''cd'''</span> <span style="color:#000000;">'''/'''</span>path<span style="color:#000000;">'''/'''</span>to<span style="color:#000000;">'''/'''</span>png<span style="color:#000000;">'''/'''</span>storage<span style="color:#000000;">'''/'''</span><span style="color:#000000;">2010</span><span style="color:#000000;">'''/'''</span>01<span style="color:#000000;">'''/'''</span>c<span style="color:#000000;">'''/'''</span>
<span style="color:#7a0874;">cd</span> <span style="color:#000000;">/</span>path<span style="color:#000000;">/</span>to<span style="color:#000000;">/</span>png<span style="color:#000000;">/</span>storage<span style="color:#000000;">/</span><span style="color:#000000;">2010</span><span style="color:#000000;">/</span>01<span style="color:#000000;">/</span>c<span style="color:#000000;">/</span>


<div style="color:#666666;">''<nowiki>## Overwrite images ##</nowiki>''</div>
<div style="color:#666666;">''<nowiki>## Overwrite images ##</nowiki>''</div>
Zeile 444: Zeile 273:
<div style="color:#666666;">''<nowiki>## Keep file system permission and make a backup of original PNG (see options below) </nowiki><nowiki>##</nowiki>''</div>
<div style="color:#666666;">''<nowiki>## Keep file system permission and make a backup of original PNG (see options below) </nowiki><nowiki>##</nowiki>''</div>


<span style="color:#000000;">'''for'''</span> i <span style="color:#000000;">'''in'''</span> <span style="color:#000000;">'''<nowiki>*</nowiki>'''</span>.png; <span style="color:#000000;">'''do'''</span> optipng <span style="color:#660033;">-o5</span> <span style="color:#660033;">-quiet</span> <span style="color:#660033;">-keep</span> <span style="color:#660033;">-preserve</span> <span style="color:#660033;">-log</span> optipng.log <span style="color:#ff0000;">"</span><span style="color:#007800;">$i</span><span style="color:#ff0000;">"</span><nowiki>; </nowiki><span style="color:#000000;">'''done'''</span>
<span style="color:#000000;">for</span> i <span style="color:#000000;">in</span> <span style="color:#000000;"><nowiki>*</nowiki></span>.png; <span style="color:#000000;">do</span> optipng <span style="color:#660033;">-o5</span> <span style="color:#660033;">-quiet</span> <span style="color:#660033;">-keep</span> <span style="color:#660033;">-preserve</span> <span style="color:#660033;">-log</span> optipng.log <span style="color:#ff0000;">"</span><span style="color:#007800;">$i</span><span style="color:#ff0000;">"</span><nowiki>; </nowiki><span style="color:#000000;">done</span>
|-
|-
|}
|}
Zeile 451: Zeile 280:
=== A note about processing *.png in all sub-directories ===
=== A note about processing *.png in all sub-directories ===


Use the find command as follows (make a backup of all images):
Use the find command as follows (make a backup of all images):\n\n{| style="border-spacing:0;width:23.83cm;"
 
 
{| style="border-spacing:0;width:23.83cm;"
|- style="border:none;padding:0.049cm;"
|- style="border:none;padding:0.049cm;"
|| <span style="color:#7a0874;">'''cd'''</span> <span style="color:#000000;">'''/'''</span>var<span style="color:#000000;">'''/'''</span>www<span style="color:#000000;">'''/'''</span>html<span style="color:#000000;">'''/'''</span>uploads<span style="color:#000000;">'''/'''</span>
|| <span style="color:#7a0874;">cd</span> <span style="color:#000000;">/</span>var<span style="color:#000000;">/</span>www<span style="color:#000000;">/</span>html<span style="color:#000000;">/</span>uploads<span style="color:#000000;">/</span>


<span style="color:#c20cb9;">'''find'''</span> . <span style="color:#660033;">-type</span> f <span style="color:#660033;">-iname</span> <span style="color:#ff0000;">"*.png"</span> <span style="color:#660033;">-print0</span> <span style="color:#000000;">'''|'''</span> <span style="color:#c20cb9;">'''xargs'''</span> <span style="color:#660033;">-I</span> <span style="color:#7a0874;">'''{}'''</span> <span style="color:#660033;">-0</span> optipng <span style="color:#660033;">-o5</span> <span style="color:#660033;">-quiet</span> <span style="color:#660033;">-keep</span> <span style="color:#660033;">-preserve</span> <span style="color:#660033;">-log</span> optipng.log <span style="color:#ff0000;">"{}"</span>
<span style="color:#c20cb9;">find</span> . <span style="color:#660033;">-type</span> f <span style="color:#660033;">-iname</span> <span style="color:#ff0000;">"*.png"</span> <span style="color:#660033;">-print0</span> <span style="color:#000000;">|</span> <span style="color:#c20cb9;">xargs</span> <span style="color:#660033;">-I</span> <span style="color:#7a0874;">{}</span> <span style="color:#660033;">-0</span> optipng <span style="color:#660033;">-o5</span> <span style="color:#660033;">-quiet</span> <span style="color:#660033;">-keep</span> <span style="color:#660033;">-preserve</span> <span style="color:#660033;">-log</span> optipng.log <span style="color:#ff0000;">"{}"</span>\n\n|-
 
 
|-
|}
|}
=== Options ===
=== Options ===
Zeile 497: Zeile 320:


     The optimization level presets
     The optimization level presets
         -o0  <<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;">>  -o1 -nx -nz</span>
         -o0  <<span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;">>  -o1 -nx -nz</span>
         -o1  <<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;">>  </span><span style="color:#000066;">'''[use the libpng heuristics]'''</span><span style="color:#660066;">  (1 trial)</span>
         -o1  <<span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;">>  </span><span style="color:#000066;">[use the libpng heuristics]</span><span style="color:#660066;">  (1 trial)</span>
         -o2  <<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;">>  -zc9 -zm8 -zs0-3 -f0,5        (8 trials)</span>
         -o2  <<span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;">>  -zc9 -zm8 -zs0-3 -f0,5        (8 trials)</span>
         -o3  <<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;">>  -zc9 -zm8-9 -zs0-3 -f0,5      (16 trials)</span>
         -o3  <<span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;">>  -zc9 -zm8-9 -zs0-3 -f0,5      (16 trials)</span>
         -o4  <<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;">>  -zc9 -zm8 -zs0-3 -f0-5        (24 trials)</span>
         -o4  <<span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;">>  -zc9 -zm8 -zs0-3 -f0-5        (24 trials)</span>
         -o5  <<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;">>  -zc9 -zm8-9 -zs0-3 -f0-5      (48 trials)</span>
         -o5  <<span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;">>  -zc9 -zm8-9 -zs0-3 -f0-5      (48 trials)</span>
         -o6  <<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;">>  -zc1-9 -zm8 -zs0-3 -f0-5      (120 trials)</span>
         -o6  <<span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;">>  -zc1-9 -zm8 -zs0-3 -f0-5      (120 trials)</span>
         -o7  <<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;">>  -zc1-9 -zm8-9 -zs0-3 -f0-5    (240 trials)</span>
         -o7  <<span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;">>  -zc1-9 -zm8-9 -zs0-3 -f0-5    (240 trials)</span>
     The libpng heuristics
     The libpng heuristics
         -o1  <<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;">>  -zc9 -zm8 -zs0 -f0            (if PLTE is present)</span>
         -o1  <<span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;">>  -zc9 -zm8 -zs0 -f0            (if PLTE is present)</span>
         -o1  <<span style="color:#000066;">'''<nowiki>=</nowiki>'''</span><span style="color:#660066;">>  -zc9 -zm8 -zs1 -f5            (if PLTE is not present)</span>
         -o1  <<span style="color:#000066;"><nowiki>=</nowiki></span><span style="color:#660066;">>  -zc9 -zm8 -zs1 -f5            (if PLTE is not present)</span>
     The most exhaustive search (not generally recommended)
     The most exhaustive search (not generally recommended)
       <span style="color:#000066;">'''[no preset]'''</span> -zc1-9 -zm1-9 -zs0-3 -f0-5    (1080 trials)
       <span style="color:#000066;">[no preset]</span> -zc1-9 -zm1-9 -zs0-3 -f0-5    (1080 trials)


Examples:
Examples:
Zeile 522: Zeile 345:
Debian / Ubuntu Linux and other operating *nix based systems can use the following tools for the same purpose:* [http://pmt.sourceforge.net/pngcrush/ pngcrush] – optimizes PNG (Portable Network Graphics) files.  
Debian / Ubuntu Linux and other operating *nix based systems can use the following tools for the same purpose:* [http://pmt.sourceforge.net/pngcrush/ pngcrush] – optimizes PNG (Portable Network Graphics) files.  
* [http://pngnq.sourceforge.net/ pngnq] – tool for optimizing PNG (Portable Network Graphics) images. It is a tool for quantizing PNG images in RGBA format.  
* [http://pngnq.sourceforge.net/ pngnq] – tool for optimizing PNG (Portable Network Graphics) images. It is a tool for quantizing PNG images in RGBA format.  
* [http://pngquant.org/ pngquant] – PNG (Portable Network Graphics) image optimising utility. It is a command-line utility for converting 24/32-bit PNG images to paletted (8-bit) PNGs.  
* [http://pngquant.org/ pngquant] – PNG (Portable Network Graphics) image optimising utility. It is a command-line utility for converting 24/32-bit PNG images to paletted (8-bit) PNGs. \n\n
 
== Weiter Informationen ==
 
 
===== Recommended readings: =====
 
# [http://optipng.sourceforge.net/pngtech/optipng.html A guide to PNG optimization].  
# [http://optipng.sourceforge.net/pngtech/optipng.html A guide to PNG optimization].  
# Visit [http://optipng.sourceforge.net/ optipng home page] to grab the latest version.  
# Visit [http://optipng.sourceforge.net/ optipng home page] to grab the latest version.  
# [https://developers.google.com/speed/ Analyze and optimize your website with PageSpeed tools].  
# [https://developers.google.com/speed/ Analyze and optimize your website with PageSpeed tools].  
# [https://www.cyberciti.biz/tips/website-load-speed-performace-testing-tools.html 6 Tools To Find Out Website Load Speed].  
# [https://www.cyberciti.biz/tips/website-load-speed-performace-testing-tools.html 6 Tools To Find Out Website Load Speed].
 
 
 
 
 


== Quellen ==
# https://www.cyberciti.biz/faq/linux-unix-optimize-lossless-png-images-with-optipng-command/


== Quellen ==


# https://www.cyberciti.biz/faq/linux-unix-optimize-lossless-png-images-with-optipng-command/
[[Kategorie:Linux/Datei/Bearbeiten]]

Aktuelle Version vom 4. Mai 2023, 10:14 Uhr

  • You have a lot of images, and want to optimize and compress the images without losing its original quality before uploading them to any cloud or local storages?
  • There are plenty of GUI applications available which will help you to optimize the images.
  • However, here are two simple command line utilities to optimize images and they are:
  1. jpegoptim – is a utility to optimize/compress JPEG files without loosing quality.
  2. OptiPNG – is a small program that optimize PNG images to smaller size without losing any information. Compress and Optimize JPEG and PNG Images in Linux

Using these two tools, you can either optimize a single or multiple images at a time.

Compress or Optimize JPEG Images from Command Line

jpegoptim

  • is a command line tool that can be used to optimize and compress JPEG, JPG and JFIF files without losing its actual quality.
  • This tool supports lossless optimization, which is based on optimizing the Huffman tables.

Install jpegoptim in Linux

# apt install jpegoptim

How to Use Jpegoptim Image Optimizer

The syntax of jpegoptm is:

$ jpegoptim filename.jpeg
$ jpegoptim [options] filename.jpeg

Let’s now compress the following tecmint.jpeg image, but before optimizing the image, first find out the actual size of the image using du as shown.

$ du -sh tecmint.jpeg 
6.2M    tecmint.jpeg

Here the actual file size is 6.2MB, now compress this file by running:

$ jpegoptim tecmint.jpeg

Optimize JPEG Image in Linux

  • Open the compressed image in any image viewer application, you will not find any major differences.
  • The source and compressed images will have the same quality.
  • The above command optimizes the images to the maximum possible size.
  • However, you can compress the given image to a specific size to, but it disables the lossless optimization.

For example, let us compress above the image from 5.6MB to around 250k.

$ jpegoptim --size=250k tecmint.jpeg

Optimize Image Fix Size

Batch JPEG Image Compression and Optimization

  • You might ask how to compress the images in the entire directory, that’s not difficult too.
  • Go to the directory where you have the images.
$ cd img/
/img $ ls -l
total 65184
-rwxr----- 1 tecmint tecmint 6680532 Jan 19 12:21 DSC_0310.JPG
-rwxr----- 1 tecmint tecmint 6846248 Jan 19 12:21 DSC_0311.JPG
-rwxr----- 1 tecmint tecmint 7174430 Jan 19 12:21 DSC_0312.JPG
-rwxr----- 1 tecmint tecmint 6514309 Jan 19 12:21 DSC_0313.JPG
-rwxr----- 1 tecmint tecmint 6755589 Jan 19 12:21 DSC_0314.JPG
-rwxr----- 1 tecmint tecmint 6789763 Jan 19 12:21 DSC_0315.JPG
-rwxr----- 1 tecmint tecmint 6958387 Jan 19 12:21 DSC_0316.JPG
-rwxr----- 1 tecmint tecmint 6463855 Jan 19 12:21 DSC_0317.JPG
-rwxr----- 1 tecmint tecmint 6614855 Jan 19 12:21 DSC_0318.JPG
-rwxr----- 1 tecmint tecmint 5931738 Jan 19 12:21 DSC_0319.JPG

And then run the following command to compress all images at once.

$ jpegoptim *.JPG
DSC_0310.JPG 6000x4000 24bit N Exif  [OK] 6680532 --> 5987094 bytes (10.38%), optimized.
DSC_0311.JPG 6000x4000 24bit N Exif  [OK] 6846248 --> 6167842 bytes (9.91%), optimized.
DSC_0312.JPG 6000x4000 24bit N Exif  [OK] 7174430 --> 6536500 bytes (8.89%), optimized.
DSC_0313.JPG 6000x4000 24bit N Exif  [OK] 6514309 --> 5909840 bytes (9.28%), optimized.
DSC_0314.JPG 6000x4000 24bit N Exif  [OK] 6755589 --> 6144165 bytes (9.05%), optimized.
DSC_0315.JPG 6000x4000 24bit N Exif  [OK] 6789763 --> 6090645 bytes (10.30%), optimized.
DSC_0316.JPG 6000x4000 24bit N Exif  [OK] 6958387 --> 6354320 bytes (8.68%), optimized.
DSC_0317.JPG 6000x4000 24bit N Exif  [OK] 6463855 --> 5909298 bytes (8.58%), optimized.
DSC_0318.JPG 6000x4000 24bit N Exif  [OK] 6614855 --> 6016006 bytes (9.05%), optimized.
DSC_0319.JPG 6000x4000 24bit N Exif  [OK] 5931738 --> 5337023 bytes (10.03%), optimized.

You can also compress multiple selected images at once:

$ jpegoptim DSC_0310.JPG DSC_0311.JPG DSC_0312.JPG 
DSC_0310.JPG 6000x4000 24bit N Exif  [OK] 6680532 --> 5987094 bytes (10.38%), optimized.
DSC_0311.JPG 6000x4000 24bit N Exif  [OK] 6846248 --> 6167842 bytes (9.91%), optimized.
DSC_0312.JPG 6000x4000 24bit N Exif  [OK] 7174430 --> 6536500 bytes (8.89%), optimized.

For more details about jpegoptim tool, check out the man pages.

$ man jpegoptim 

Compress or Optimize PNG Images from Command Line

  • OptiPNG is a command line tool used to optimize and compress PNG (portable network graphics) files without losing its original quality.
  • The installation and usage of OptiPNG is very similar to jpegoptim.

Install OptiPNG in Linux

# apt-get install optipng

How to Use OptiPNG Image Optimizer

The general syntax of optipng is:

$ optipng filename.png
$ optipng [options] filename.png

Let us compress the tecmint.png image, but before optimizing, first check the actual size of the image as shown:

 $ ls -lh tecmint.png 
-rw------- 1 tecmint tecmint 350K Jan 19 12:54 tecmint.png

Here the actual file size of above image is 350K, now compress this file by running:

$ optipng tecmint.png
OptiPNG 0.6.4: Advanced PNG optimizer.
Copyright (C) 2001-2010 Cosmin Truta.
** Processing: tecmint.png
1493x914 pixels, 4x8 bits/pixel, RGB+alpha
Reducing image to 3x8 bits/pixel, RGB
Input IDAT size = 357525 bytes
Input file size = 358098 bytes
Trying:
 zc = 9  zm = 8  zs = 0  f = 0         IDAT size = 249211
Selecting parameters:
 zc = 9  zm = 8  zs = 0  f = 0         IDAT size = 249211
Output IDAT size = 249211 bytes (108314 bytes decrease)
Output file size = 249268 bytes (108830 bytes = 30.39% decrease)
  • As you see in the above output, the size of the tecmint.png file has been reduced up to 30.39%.
  • Now verify the file size again using:
$ ls -lh tecmint.png 
-rw-r--r-- 1 tecmint tecmint 244K Jan 19 12:56 tecmint.png

Open the compressed image in any image viewer application, you will not find any major differences between the original and compressed files. The source and compressed images will have the same quality.

Batch PNG Image Compression and Optimization

To compress batch or multiple PNG images at once, just go the directory where all images resides and run the following command to compress.

$ cd img/
$ optipng *.png

OptiPNG 0.6.4: Advanced PNG optimizer. Copyright (C) 2001-2010 Cosmin Truta.

** Processing: Debian-8.png
720x345 pixels, 3x8 bits/pixel, RGB
Input IDAT size = 95151 bytes
Input file size = 95429 bytes
Trying:
 zc = 9  zm = 8  zs = 0  f = 0         IDAT size = 81388
Selecting parameters:
 zc = 9  zm = 8  zs = 0  f = 0         IDAT size = 81388
Output IDAT size = 81388 bytes (13763 bytes decrease)
Output file size = 81642 bytes (13787 bytes = 14.45% decrease)

** Processing: Fedora-22.png
720x345 pixels, 4x8 bits/pixel, RGB+alpha
Reducing image to 3x8 bits/pixel, RGB
Input IDAT size = 259678 bytes
Input file size = 260053 bytes

Trying:
 zc = 9  zm = 8  zs = 0  f = 5         IDAT size = 222479
 zc = 9  zm = 8  zs = 1  f = 5         IDAT size = 220311
 zc = 1  zm = 8  zs = 2  f = 5         IDAT size = 216744

Selecting parameters:
 zc = 1  zm = 8  zs = 2  f = 5         IDAT size = 216744

Output IDAT size = 216744 bytes (42934 bytes decrease)
Output file size = 217035 bytes (43018 bytes = 16.54% decrease)
....

For more details about optipng check man pages.

$ man optipng

Quellen

  1. https://www.tecmint.com/optimize-and-compress-jpeg-or-png-batch-images-linux-commandline/

Optimize and Compress PNG Files In Bulk

I have lots of images in png format (over 250k+ png). Properly formatting and compressing png images can save many bytes of data. How do I compress and optimize png images on my amazon cloud account so that I can save bandwidth on cloudfront cdn account? How do I use an image compressor to create lossless compression on PNG files, with no effect on image quality in bulk using Red Hat Enterprise Linux bash shell?The following image format is recommended and used by big web sites such as Google / Yahoo / Amazon / Facebook etc:\n\n# PNG file format is recommended for web.

  1. GIF file format is recommended for small size images.
  2. JPG file format is recommended for high resolution photographic-style images.
  3. Do not use BMPs or TIFFs. \n\n

Say hello to optipng

  • You need to use a tool called optipng.
  • It is a PNG optimizer that recompresses image files to a smaller size, without losing any information.
  • This program also converts external formats (BMP, GIF, PNM and TIFF) to optimized PNG, and performs PNG integrity checks and corrections.
  • This tool can be installed on any server powered by Unix or Linux operating systems.

Installation

$ sudo apt-get install optipng 

How do I use optipng command?

The syntax is:

optipng file

optipng [options] file

optipng [options] input.png |- |} My sample test.png image:

To display png image size, type, and compression info, enter:$ pnginfo -t test.png Sample outputs:

test.png (tiffinfo compatible labels)...

 Image Width: 1164 Image Length: 911
 Bit/Sample: 8
 Samples/Pixel: 3
 Pixel Depth: 24
 Colour Type (Photometric Interpretation): RGB 
 Image filter: Single row per byte filter 
 Interlacing: No interlacing 
 Compression Scheme: Deflate method 8, 32k window
 Resolution: 0, 0 (unit unknown)
 FillOrder: msb-to-lsb
 Byte Order: Network (Big Endian)
 Number of text strings: 1 of 9
   Software (xTXt deflate compressed): Shutter

Use ls command to see file size:$ ls -lh test.png Sample outputs:

-rw-r--r-- 1 vivek vivek 279K Nov 29 00:10 test.png

Use optipng optimization program as follows:$ cp test.{png,bak}$ optipng test.pngSample outputs:

OptiPNG 0.6.4: Advanced PNG optimizer.

Copyright (C) 2001-2010 Cosmin Truta.


** Processing: test.png

1164x911 pixels, 3x8 bits/pixel, RGB

Input IDAT size = 284778 bytes

Input file size = 285286 bytes


Trying:

 zc = 9  zm = 8  zs = 0  f = 0         IDAT size = 215274

Selecting parameters:

 zc = 9  zm = 8  zs = 0  f = 0         IDAT size = 215274

Output IDAT size = 215274 bytes (69504 bytes decrease)

Output file size = 215374 bytes (69912 bytes = 24.51% decrease)

File size is reduced by 24.51%:$ ls -lh test.pngSample outputs:-rw-r--r-- 1 vivek vivek 211K Nov 29 02:40 test.pngYou can verify the quality of both images (click to enlarge):\n\n

Optimized test.png file ensures that it loads faster for users on slow connections. It will also save 24.51% bytes per image view in terms of both network bandwidth and storage. According to Google:

You should see a benefit for any image file that can be reduced by 25 bytes or more (less than this will not result in any appreciable performance gain).

How do I optimize files in bulk?

Use a bash for loop as follows:\n\n{| style="border-spacing:0;width:20.652cm;" |- style="border:none;padding:0.049cm;"

||

#!/bin/bash

cd /path/to/png/storage/2010/01/c/

mkdir optimized

## store optimized images in optimized directory ##
## Keep file system permission and make a backup of original PNG (see options below) ##

for i in *.png; do optipng -o5 -quiet -keep -preserve -dir optimized -log optipng.log "$i"; done |- |} You need to make changes to your code. For example, url path to optimize url will be as follows:test.pngAlternatively, you can overwrite existing PNG images:\n\n{| style="border-spacing:0;width:18.958cm;" |- style="border:none;padding:0.049cm;"

||

#!/bin/bash

cd /path/to/png/storage/2010/01/c/

## Overwrite images ##
## Keep file system permission and make a backup of original PNG (see options below) ##

for i in *.png; do optipng -o5 -quiet -keep -preserve -log optipng.log "$i"; done |- |} Next, purge all images from your CDN account. See how to purge old images / invalidating object from cloud front for more information.

A note about processing *.png in all sub-directories

Use the find command as follows (make a backup of all images):\n\n{| style="border-spacing:0;width:23.83cm;" |- style="border:none;padding:0.049cm;" || cd /var/www/html/uploads/

find . -type f -iname "*.png" -print0 | xargs -I {} -0 optipng -o5 -quiet -keep -preserve -log optipng.log "{}"\n\n|- |}

Options

General options:

   -fix                enable error recovery
   -force              enforce writing of a new output file
   -keep               keep a backup of the modified files
   -preserve           preserve file attributes if possible
   -quiet              quiet mode
   -simulate           simulation mode
   -snip               cut one image out of multi-image or animation files
   -out <file>         write output file to <file>
   -dir <directory>    write output file(s) to <directory>
   -log <file>         log messages to <file>
   --                  stop option switch parsing

Optimization options:

   -f  <filters>       PNG delta filters (0-5)                 default 0,5
   -i  <type>          PNG interlace type (0-1)                default <input>
   -zc <levels>        zlib compression levels (1-9)           default 9
   -zm <levels>        zlib memory levels (1-9)                default 8
   -zs <strategies>    zlib compression strategies (0-3)       default 0-3
   -zw <window size>   zlib window size (32k,16k,8k,4k,2k,1k,512,256)
   -full               produce a full report on IDAT (might reduce speed)
   -nb                 no bit depth reduction
   -nc                 no color type reduction
   -np                 no palette reduction
   -nx                 no reductions
   -nz                 no IDAT recoding

Optimization details:

   The optimization level presets
       -o0  <=>  -o1 -nx -nz
       -o1  <=>  [use the libpng heuristics]   (1 trial)
       -o2  <=>  -zc9 -zm8 -zs0-3 -f0,5        (8 trials)
       -o3  <=>  -zc9 -zm8-9 -zs0-3 -f0,5      (16 trials)
       -o4  <=>  -zc9 -zm8 -zs0-3 -f0-5        (24 trials)
       -o5  <=>  -zc9 -zm8-9 -zs0-3 -f0-5      (48 trials)
       -o6  <=>  -zc1-9 -zm8 -zs0-3 -f0-5      (120 trials)
       -o7  <=>  -zc1-9 -zm8-9 -zs0-3 -f0-5    (240 trials)
   The libpng heuristics
       -o1  <=>  -zc9 -zm8 -zs0 -f0            (if PLTE is present)
       -o1  <=>  -zc9 -zm8 -zs1 -f5            (if PLTE is not present)
   The most exhaustive search (not generally recommended)
     [no preset] -zc1-9 -zm1-9 -zs0-3 -f0-5    (1080 trials)

Examples:

   optipng file.png                            (default speed)
   optipng -o5 file.png                        (moderately slow)
   optipng -o7 file.png                        (very slow)
   optipng -i1 -o7 -v -full -sim experiment.png

Other png optimization tools for Linux / Unix

Debian / Ubuntu Linux and other operating *nix based systems can use the following tools for the same purpose:* pngcrush – optimizes PNG (Portable Network Graphics) files.

  • pngnq – tool for optimizing PNG (Portable Network Graphics) images. It is a tool for quantizing PNG images in RGBA format.
  • pngquant – PNG (Portable Network Graphics) image optimising utility. It is a command-line utility for converting 24/32-bit PNG images to paletted (8-bit) PNGs. \n\n

Weiter Informationen

  1. A guide to PNG optimization.
  2. Visit optipng home page to grab the latest version.
  3. Analyze and optimize your website with PageSpeed tools.
  4. 6 Tools To Find Out Website Load Speed.

Quellen

  1. https://www.cyberciti.biz/faq/linux-unix-optimize-lossless-png-images-with-optipng-command/