You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added an install script to make it easier for people to install the application.
- Minor changes to the build and main method to make it easier to call from the script.
Created by [Eric Perret](https://www.ericperret.org)
8
6
9
7
## Summary ##
10
8
11
-
ImageOptimization is a JAVA batch program / service used to optimize images by reducing the size (less bytes) of images without changing the quality of the images. This process is called [lossless compression](http://en.wikipedia.org/wiki/Image_compression#Lossy_and_lossless_compression).
9
+
ImageOptimization is a JAVA batch program / service used to optimize images by reducing the size (less bytes) of images without changing the quality of the images. This process is called [lossless compression](https://en.wikipedia.org/wiki/Image_compression#Lossy_and_lossless_image_compression).
12
10
13
11
Apart from optimizing an image, it also supports a few other things
12
+
14
13
* Converting image types, GIFs to PNGs, if it will make the image smaller.
15
14
* Create a Chrome (browser) specific version, [WebP](https://developers.google.com/speed/webp/?csw=1)
16
15
* Automated validation of images.
17
16
18
-
## Installation ##
17
+
## Getting Started ##
18
+
19
+
## 🚀 Quick Install & Setup ##
20
+
21
+
We provide a helper script to automate the installation of the Java application and all required binary dependencies (including `pngout`, `optipng`, `jpegtran`, etc.).
22
+
23
+
### Installation ###
24
+
25
+
Run the management script located in the `script/` directory. This script detects your OS (Linux/Mac), installs system tools via `apt` or `brew`, builds the project, and configures the `image-optimizer` command.
26
+
27
+
```bash
28
+
# 1. Give execution permission to the script
29
+
chmod +x script/install.sh
30
+
31
+
# 2. Run the installer
32
+
./script/install.sh
33
+
```
34
+
35
+
This will install the application for the current user so it can be called from anywhere using the following command.
To remove the application and all installed files, run:
44
+
45
+
```bash
46
+
./script/install.sh uninstall
47
+
```
48
+
49
+
This will remove:
50
+
51
+
* The `image-optimizer` wrapper script from `~/.local/bin/`
52
+
* The entire installation directory at `~/.local/share/ImageOptimization/`
53
+
54
+
Note: This does not remove system packages (like Maven, ImageMagick, etc.) that were installed via package managers (apt/brew). Those must be removed manually if desired.
55
+
56
+
## Full Install & Setup ##
19
57
20
58
### Prerequisites ###
21
59
22
60
* Some version of **Git**
23
61
* If you are on the Mac, you should already have the command line version of git installed.
24
-
* For other OSs or for the GUI version, they can be downloaded [here](http://git-scm.com/downloads).
62
+
* For other OSs or for the GUI version, [download Git from git-scm.com](https://git-scm.com/install/).
25
63
***JDK 8**
26
-
*[download it from Oracle](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
27
-
***[Apache Maven](http://maven.apache.org/download.cgi) 3.3** or later
64
+
*[Download JDK 17 from Oracle](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) or later
65
+
***[Apache Maven](https://maven.apache.org/download.cgi) 3.3** or later
28
66
29
67
A few binaries needed by the code have to be installed on the OS.
30
68
31
-
_Note: This only works on Linux and has only been tested on Ubuntu. There are a number of non-java binaries that are required for this project and I have only tried compiling them for for Linux, specifically Ubuntu._
69
+
_Note: This only works on Linux (only been tested on Ubuntu) and Mac. There are a number of non-java binaries that are required for this project and I have only tried compiling them for for Linux, specifically Ubuntu, and Mac._
70
+
32
71
*[ImageMagick](https://www.imagemagick.org/script/binary-releases.php) needs to be installed on the system (used for converting images because JAVA cannot handle certain file types).
33
72
* The following binaries need to be compiled into the root of the project in the `<PROJECT_DIRECTORY>/lib/binary/linux` directory.
The `<PATH_TO_BINARIES_DIRECTORY>` is the path where the binaries exist that are used to optimize the images. By default the code will look for the binaries in the `./lib/binary/linux/` directory
70
110
71
111
You can also call this code programmatically from existing JAVA code by using the API, `com.salesforce.perfeng.uiperf.imageoptimization.service.ImageOptimizationService.optimizeAllImages(FileTypeConversion, boolean, Collection<File>)`.
72
112
73
113
Example:
74
114
75
-
final IImageOptimizationService<Void> service = new ImageOptimizationService.createInstance(<PATH_TO_BINARIES_DIRECTORY>);
76
-
final List<OptimizationResult<Void>> list = service.optimizeAllImages(FileTypeConversion.NONE, false, new File("path/to/image.jpg"), File("path/to/image2.jpg"));
77
-
System.out.println(list);
115
+
```java
116
+
finalIImageOptimizationService<Void> service =newImageOptimizationService.createInstance(<PATH_TO_BINARIES_DIRECTORY>);
117
+
finalList<OptimizationResult<Void>> list = service.optimizeAllImages(FileTypeConversion.NONE, false, newFile("path/to/image.jpg"), File("path/to/image2.jpg"));
118
+
System.out.println(list);
119
+
```
78
120
79
121
The main API is `ImageOptimizationService.optimizeAllImages`.
122
+
80
123
* The 1st argument indicates if / how the image should be converted. There are currently 3 types of conversion. `FileTypeConversion.NONE`: None of the images will be converted to a different files type; `FileTypeConversion.ALL`: There are no restrictions around which images will be converted to different images types as long as it results in a smaller file size (less bytes) and optimization is lossless; `FileTypeConversion.IE6SAFE`: The same as `ALL` except that it will not convert the image if it is a GIF with Alpha transparency. PNG files with transparency, when loaded in IE6, show the transparent parts as gray.
81
124
* The 2nd argument indicates if browser specific versions of the file should be generated in addition to the optimized version of the image.
82
125
* The 3rd argument is the collection of image files to optimize.
@@ -85,11 +128,11 @@ The function returns a list of `OptimizationResult` objects.
85
128
86
129
### How is the Optimization Actually Accomplished? ###
87
130
88
-
The heavy lifing is done by 6 different binary applications: [advpng](http://advancemame.sourceforge.net/doc-advpng.html), [gifsicle](http://www.lcdf.org/gifsicle/), [jfifremove](https://lyncd.com/files/imgopt/jfifremove.c), [jpegtran](http://jpegclub.org/jpegtran/), [optipng](http://optipng.sourceforge.net/), [pngout](http://advsys.net/ken/utils.htm), [pngquant](https://pngquant.org/).
131
+
The heavy lifing is done by 6 different binary applications: [advpng](https://www.advancemame.it/doc-advpng.html), [gifsicle](https://www.lcdf.org/gifsicle/), [jfifremove](https://lyncd.com/files/imgopt/jfifremove.c), [jpegtran](https://jpegclub.org/jpegtran/), [optipng](https://optipng.sourceforge.net/), [pngout](https://www.jonof.id.au/kenutils.html), [pngquant](https://pngquant.org/).
89
132
90
133
The JAVA code calls out to these binaries and using the appropriate ones for the image format. The code does this twice. For some reason passing in an already optimized image will result in a few bytes reduction the second time it is optimized.
91
134
92
-
For converting the images we use 3 binaries: [ImageMagick](http://www.imagemagick.org/), [cwebp](https://developers.google.com/speed/webp/docs/cwebp), [gif2webp](https://developers.google.com/speed/webp/docs/gif2webp).
135
+
For converting the images we use 3 binaries: [ImageMagick](https://imagemagick.org/), [cwebp](https://developers.google.com/speed/webp/docs/cwebp), [gif2webp](https://developers.google.com/speed/webp/docs/gif2webp).
0 commit comments