Skip to content

Commit c816fe0

Browse files
authored
feat: added install script (#16)
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.
1 parent 28a5e7d commit c816fe0

File tree

5 files changed

+439
-27
lines changed

5 files changed

+439
-27
lines changed

.project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,15 @@
3333
<nature>org.eclipse.jdt.core.javanature</nature>
3434
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
3535
</natures>
36+
<filteredResources>
37+
<filter>
38+
<id>1769460831746</id>
39+
<name></name>
40+
<type>30</type>
41+
<matcher>
42+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
43+
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
44+
</matcher>
45+
</filter>
46+
</filteredResources>
3647
</projectDescription>

README.md

Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,91 @@
11
# ImageOptimization - Library for losslessly optimizing images #
22

3-
Copyright (c) 2016, Salesforce.com. All rights reserved.
3+
Copyright (c) 2026, Salesforce.com. All rights reserved.
44

5-
Created by <span itemscope="" itemtype="http://schema.org/Person">
6-
<a itemprop="url" rel="author" href="https://github.com/eperret"><span itemprop="name">Eric Perret</span></a>
7-
</span>
5+
Created by [Eric Perret](https://www.ericperret.org)
86

97
## Summary ##
108

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).
1210

1311
Apart from optimizing an image, it also supports a few other things
12+
1413
* Converting image types, GIFs to PNGs, if it will make the image smaller.
1514
* Create a Chrome (browser) specific version, [WebP](https://developers.google.com/speed/webp/?csw=1)
1615
* Automated validation of images.
1716

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.
36+
37+
```bash
38+
image-optimizer path/to/image.png path/to/folder/of/images/
39+
```
40+
41+
### Uninstallation ###
42+
43+
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 ##
1957

2058
### Prerequisites ###
2159

2260
* Some version of **Git**
2361
* 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/).
2563
* **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
2866

2967
A few binaries needed by the code have to be installed on the OS.
3068

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+
3271
* [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).
3372
* The following binaries need to be compiled into the root of the project in the `<PROJECT_DIRECTORY>/lib/binary/linux` directory.
34-
* advpng ([source](https://github.com/amadvance/advancecomp/), [homepage](http://advancemame.sourceforge.net/doc-advpng.html))
35-
* gifsicle ([source](https://www.lcdf.org/gifsicle/gifsicle-1.88.tar.gz), [homepage](https://www.lcdf.org/gifsicle/))
36-
* jfifremove ([source](https://lyncd.com/files/imgopt/jfifremove.c))
37-
* jpegtran ([source](http://www.ijg.org/files/jpegsrc.v9b.tar.gz), [homepage](http://jpegclub.org/jpegtran/))
38-
* optipng ([source](http://prdownloads.sourceforge.net/optipng/optipng-0.7.5.tar.gz?download), [homepage](http://optipng.sourceforge.net/))
39-
* pngout ([source](http://www.jonof.id.au/kenutils), [homepage](http://advsys.net/ken/utils.htm))
73+
* advpng ([source](https://github.com/amadvance/advancecomp/), [homepage](https://www.advancemame.it/doc-advpng.html))
74+
* gifsicle ([source](https://github.com/kohler/gifsicle), [homepage](https://www.lcdf.org/gifsicle/))
75+
* jfifremove ([source](https://github.com/x2q/imgopt/blob/master/jfifremove.c))
76+
* jpegtran ([source](https://www.ijg.org/files/), [homepage](https://jpegclub.org/jpegtran/))
77+
* optipng ([source](https://prdownloads.sourceforge.net/optipng/optipng-7.9.1.tar.gz?download), [homepage](https://optipng.sourceforge.net/))
78+
* pngout ([source](https://www.jonof.id.au/kenutils.html), [homepage](https://www.jonof.id.au/kenutils.html))
4079
* cwebp ([source](https://storage.googleapis.com/downloads.webmproject.org/releases/webp/index.html), [homepage](https://developers.google.com/speed/webp/docs/cwebp))
4180
* gif2webp ([source](https://storage.googleapis.com/downloads.webmproject.org/releases/webp/index.html), [homepage](https://developers.google.com/speed/webp/docs/gif2webp))
42-
* pngquant ([source](https://github.com/pornel/pngquant), [homepage](https://pngquant.org/))
43-
81+
* pngquant ([source](https://github.com/kornelski/pngquant), [homepage](https://pngquant.org/))
4482

4583
### Additional Maven set up ###
4684

47-
Maven uses the JDK pointed to be the `JAVA_HOME` environment variable. Verify that Maven is using JDK 8, for example:
85+
Maven uses the JDK pointed to be the `JAVA_HOME` environment variable. Verify that Maven is using JDK 17+, for example:
4886
Maven 3.3.3+ is recommended.
4987

50-
```
88+
```bash
5189
$ mvn --version
5290

5391
Apache Maven 3.3.3 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 05:51:28-0800)
@@ -64,19 +102,24 @@ There are 2 ways that the library can be used:
64102

65103
Calling the main method from the commandline with a list of files or folders.
66104

67-
java -jar ImageOptimization-1.2.jar -DbinariesDirectory=<PATH_TO_BINARIES_DIRECTORY> path/to/image.png path/to/folder/of/images/
105+
```bash
106+
java -jar ImageOptimization-1.2.jar -DbinariesDirectory=<PATH_TO_BINARIES_DIRECTORY> path/to/image.png path/to/folder/of/images/
107+
```
68108

69109
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
70110

71111
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>)`.
72112

73113
Example:
74114

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+
final IImageOptimizationService<Void> service = new ImageOptimizationService.createInstance(<PATH_TO_BINARIES_DIRECTORY>);
117+
final List<OptimizationResult<Void>> list = service.optimizeAllImages(FileTypeConversion.NONE, false, new File("path/to/image.jpg"), File("path/to/image2.jpg"));
118+
System.out.println(list);
119+
```
78120

79121
The main API is `ImageOptimizationService.optimizeAllImages`.
122+
80123
* 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.
81124
* The 2nd argument indicates if browser specific versions of the file should be generated in addition to the optimized version of the image.
82125
* The 3rd argument is the collection of image files to optimize.
@@ -85,11 +128,11 @@ The function returns a list of `OptimizationResult` objects.
85128

86129
### How is the Optimization Actually Accomplished? ###
87130

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/).
89132

90133
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.
91134

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).
93136

94137
### Automated Validation ###
95138

pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ Note: It only runs on Linux and requires additional binaries</description>
103103
<artifactId>maven-compiler-plugin</artifactId>
104104
<version>3.8.1</version>
105105
</plugin>
106+
<plugin>
107+
<groupId>org.apache.maven.plugins</groupId>
108+
<artifactId>maven-jar-plugin</artifactId>
109+
<version>3.3.0</version>
110+
<configuration>
111+
<archive>
112+
<manifest>
113+
<mainClass>com.salesforce.perfeng.uiperf.imageoptimization.Main</mainClass>
114+
</manifest>
115+
</archive>
116+
</configuration>
117+
</plugin>
106118
<plugin>
107119
<groupId>org.apache.maven.plugins</groupId>
108120
<artifactId>maven-source-plugin</artifactId>
@@ -120,6 +132,30 @@ Note: It only runs on Linux and requires additional binaries</description>
120132
<artifactId>maven-surefire-plugin</artifactId>
121133
<version>2.22.2</version>
122134
</plugin>
135+
<plugin>
136+
<groupId>org.apache.maven.plugins</groupId>
137+
<artifactId>maven-assembly-plugin</artifactId>
138+
<version>3.6.0</version>
139+
<configuration>
140+
<descriptorRefs>
141+
<descriptorRef>jar-with-dependencies</descriptorRef>
142+
</descriptorRefs>
143+
<archive>
144+
<manifest>
145+
<mainClass>com.salesforce.perfeng.uiperf.imageoptimization.Main</mainClass>
146+
</manifest>
147+
</archive>
148+
</configuration>
149+
<executions>
150+
<execution>
151+
<id>make-assembly</id>
152+
<phase>package</phase>
153+
<goals>
154+
<goal>single</goal>
155+
</goals>
156+
</execution>
157+
</executions>
158+
</plugin>
123159
</plugins>
124160
</build>
125161

0 commit comments

Comments
 (0)