Skip to content

Commit b5244f3

Browse files
committed
Version 1.5.0
Added ability to chose which resolutions go into the icns file in the GUI.
1 parent 91a0a6b commit b5244f3

24 files changed

+559
-178
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Then, try to process your image again but this time when it exits, it should kic
5353
The program takes your 1024 x 1024 image file and it creates a folder where it then converts your image into the different sizes that are needed for the final `.icns` file. Then it calls `iconutil` to do the conversion. It will use the original name of your file but it will have `.icns` as the extension name and it will drop it into the same folder that your selected image file resides in.
5454

5555
## Updates
56+
* 1.5.0
57+
* Added ability to chose which resolutions go into the icns file in the GUI.
5658
* 1.4.0
5759
* Facelift - along with major functionality enhancements
5860
* 1.3.2

dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
<properties>
112112
<maven.compiler.release>20</maven.compiler.release>
113113
<versions-maven-plugin>2.16.2</versions-maven-plugin>
114-
<mainClass>com.simtechdata.Main</mainClass>
114+
<mainClass>com.simtechdata.MainGUI</mainClass>
115115
<maven-surefire-plugin>3.2.2</maven-surefire-plugin>
116116
<native-maven-plugin>0.9.28</native-maven-plugin>
117117
<javapackager>1.7.2</javapackager>

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
<groupId>com.simtechdata</groupId>
88
<artifactId>MacIcns</artifactId>
9-
<version>1.4.0</version>
9+
<version>1.5.0</version>
1010
<packaging>jar</packaging>
1111

1212
<properties>
1313
<maven.compiler.release>20</maven.compiler.release>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
<mainClass>com.simtechdata.Main</mainClass>
15+
<mainClass>com.simtechdata.MainGUI</mainClass>
1616
<javafx.version>21-ea+24</javafx.version>
1717
<javapackager>1.7.2</javapackager>
1818
<maven-jar-plugin>3.3.0</maven-jar-plugin>

src/main/java/com/simtechdata/ImageChecker.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.simtechdata;
22

3+
import javafx.scene.image.Image;
4+
35
import java.io.File;
46
import java.io.FileInputStream;
57
import java.io.IOException;
@@ -13,7 +15,10 @@ public static boolean isValid(File file) {
1315
int bytesRead = fis.read(header);
1416
if (bytesRead >= 8) {
1517
if (isPNG(header) || isJPEG(header) || isGIF(header) || isTIFF(header) || isBMP(header) || isSVG(file)) {
16-
return true;
18+
Image image = new Image(file.toPath().toUri().toString());
19+
double imgWidth = image.getWidth();
20+
double imgHeight = image.getHeight();
21+
return imgWidth == 1024.0 && imgHeight == 1024.0;
1722
}
1823
}
1924
} catch (IOException e) {

src/main/java/com/simtechdata/Main.java renamed to src/main/java/com/simtechdata/MainGUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.nio.file.Paths;
88

99

10-
public class Main extends Application {
10+
public class MainGUI extends Application {
1111

1212
private static Path mainPath;
1313

@@ -19,7 +19,7 @@ public static void main(String[] args) {
1919
}
2020
if (mainPath != null) {
2121
if (mainPath.toFile().exists()) {
22-
new ProcessFile(mainPath, false).run();
22+
new ProcessFile(mainPath,null).run();
2323
}
2424
else {
2525
System.out.println("No file exists at this path: " + args[0]);
Lines changed: 87 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.simtechdata;
22

3+
import com.simtechdata.build.Job;
4+
import com.simtechdata.build.Selections;
35
import javafx.scene.image.Image;
4-
import javafx.scene.image.WritableImage;
5-
import javafx.scene.paint.Color;
66
import org.apache.commons.io.FileUtils;
77
import org.apache.commons.io.FilenameUtils;
8-
import org.glavo.png.javafx.PNGJavaFXUtils;
98

109
import java.io.File;
1110
import java.io.IOException;
@@ -17,16 +16,18 @@
1716

1817
public class ProcessFile {
1918

20-
public ProcessFile(Path selectedImageFile, boolean inWindow) {
19+
public ProcessFile(Path selectedImageFile, Selections selections) {
2120
this.selectedImageFile = selectedImageFile;
22-
this.inWindow = inWindow;
21+
this.selections = selections;
2322
}
2423

2524
private final Path selectedImageFile;
26-
private final boolean inWindow;
25+
private final Selections selections;
2726

2827
public Response run() {
29-
return processFile();
28+
if(selections == null)
29+
return processFileShell();
30+
return processFileGUI();
3031
}
3132

3233
private static String icnsFilePath;
@@ -35,24 +36,75 @@ public static String getIcnsFilePath() {
3536
return icnsFilePath;
3637
}
3738

38-
private Response processFile() {
39+
private Response processFileGUI() {
40+
Response response = new Response();
41+
if (selectedImageFile != null) {
42+
Map<Integer, Job> jobMap = selections.getJobMap();
43+
if(jobMap == null) {
44+
System.out.println("NULL");
45+
System.exit(0);
46+
}
47+
try {
48+
File file = selectedImageFile.toFile();
49+
Image original = new Image(file.toURI().toString());
50+
double width = original.getWidth();
51+
double height = original.getHeight();
52+
String msg;
53+
if (!ImageChecker.isValid(file)) {
54+
msg = "Specified file is not a valid image type.\nMust be: PNG, JPEG, GIF, TIFF, BMP or SVG";
55+
response.set(false, msg);
56+
return response;
57+
}
58+
if (width != 1024 || height != 1024) {
59+
msg = "Specified image is not 1024 x 1024 in size";
60+
response.set(false, msg);
61+
return response;
62+
}
63+
if(selections.makeParentFolder()) {
64+
for (int index : jobMap.keySet()) {
65+
jobMap.get(index).saveFile();
66+
}
67+
int exitCode = new Run(selections.getIconFolder(), selections.getIcnsFilePath()).run();
68+
if (exitCode != 0) {
69+
response.set(false, "Error occurred while running the icon creation process");
70+
}
71+
else {
72+
FileUtils.deleteDirectory(selections.getIconFolder().toFile());
73+
response.set(true, "");
74+
}
75+
}
76+
else {
77+
msg = "Could not create the icon workspace folder, permission issue?";
78+
response.set(false, msg);
79+
}
80+
}
81+
catch (IOException e) {
82+
throw new RuntimeException(e);
83+
}
84+
}
85+
return response;
86+
}
87+
88+
private Response processFileShell() {
3989
Response response = new Response();
4090
if (selectedImageFile != null) {
4191
String folder = selectedImageFile.toFile().getParentFile().getAbsolutePath();
4292
Path iconFolder = Paths.get(folder, "icon.iconset");
4393
String iconFilename = FilenameUtils.getBaseName(selectedImageFile.toString()) + ".icns";
4494
Path icnsFile = Paths.get(folder, iconFilename);
4595
icnsFilePath = icnsFile.toAbsolutePath().toString();
46-
Path Image01 = Paths.get(iconFolder.toString(), "icon_512x512@2x.png");
47-
Path Image02 = Paths.get(iconFolder.toString(), "icon_512x512.png");
48-
Path Image03 = Paths.get(iconFolder.toString(), "icon_256x256@2x.png");
49-
Path Image04 = Paths.get(iconFolder.toString(), "icon_256x256.png");
50-
Path Image05 = Paths.get(iconFolder.toString(), "icon_128x128@2x.png");
51-
Path Image06 = Paths.get(iconFolder.toString(), "icon_128x128.png");
52-
Path Image07 = Paths.get(iconFolder.toString(), "icon_32x32@2x.png");
53-
Path Image08 = Paths.get(iconFolder.toString(), "icon_32x32.png");
54-
Path Image09 = Paths.get(iconFolder.toString(), "icon_16x16@2x.png");
55-
Path Image10 = Paths.get(iconFolder.toString(), "icon_16x16.png");
96+
Path Image01 = Paths.get(iconFolder.toString(), "icon_512x512@2x.png"); //01
97+
Path Image02 = Paths.get(iconFolder.toString(), "icon_512x512.png"); //02
98+
Path Image03 = Paths.get(iconFolder.toString(), "icon_256x256@2x.png"); //03
99+
Path Image04 = Paths.get(iconFolder.toString(), "icon_256x256.png"); //04
100+
Path Image05 = Paths.get(iconFolder.toString(), "icon_128x128@2x.png"); //05
101+
Path Image06 = Paths.get(iconFolder.toString(), "icon_128x128.png"); //06
102+
Path Image07 = Paths.get(iconFolder.toString(), "icon_64x64@2x.png"); //07
103+
Path Image08 = Paths.get(iconFolder.toString(), "icon_64x64.png"); //08
104+
Path Image09 = Paths.get(iconFolder.toString(), "icon_32x32@2x.png"); //09
105+
Path Image10 = Paths.get(iconFolder.toString(), "icon_32x32.png"); //10
106+
Path Image11 = Paths.get(iconFolder.toString(), "icon_16x16@2x.png"); //11
107+
Path Image12 = Paths.get(iconFolder.toString(), "icon_16x16.png"); //12
56108

57109
Map<Integer, Job> jobMap = new HashMap<>();
58110

@@ -64,21 +116,13 @@ private Response processFile() {
64116
String msg;
65117
if (!ImageChecker.isValid(file)) {
66118
msg = "Specified file is not a valid image type.\nMust be: PNG, JPEG, GIF, TIFF, BMP or SVG";
67-
if (!inWindow) {
68-
System.out.println(msg);
69-
System.exit(0);
70-
}
71-
response.set(false, msg);
72-
return response;
119+
System.out.println(msg);
120+
System.exit(0);
73121
}
74122
if (width != 1024 || height != 1024) {
75123
msg = "Specified image is not 1024 x 1024 in size";
76-
if (!inWindow) {
77-
System.out.println(msg);
78-
System.exit(0);
79-
}
80-
response.set(false, msg);
81-
return response;
124+
System.out.println(msg);
125+
System.exit(0);
82126
}
83127
if (FileUtils.createParentDirectories(Image01.toFile()).exists()) {
84128
jobMap.put(1, new Job(original, Image01, 1024));
@@ -87,10 +131,12 @@ private Response processFile() {
87131
jobMap.put(4, new Job(original, Image04, 256));
88132
jobMap.put(5, new Job(original, Image05, 256));
89133
jobMap.put(6, new Job(original, Image06, 128));
90-
jobMap.put(7, new Job(original, Image07, 64));
91-
jobMap.put(8, new Job(original, Image08, 32));
92-
jobMap.put(9, new Job(original, Image09, 32));
93-
jobMap.put(10, new Job(original, Image10, 16));
134+
jobMap.put(7, new Job(original, Image07, 128));
135+
jobMap.put(8, new Job(original, Image08, 64));
136+
jobMap.put(9, new Job(original, Image09, 64));
137+
jobMap.put(10, new Job(original, Image10, 32));
138+
jobMap.put(11, new Job(original, Image11, 32));
139+
jobMap.put(12, new Job(original, Image12, 16));
94140

95141
for (int index : jobMap.keySet()) {
96142
jobMap.get(index).saveFile();
@@ -102,88 +148,23 @@ private Response processFile() {
102148
}
103149
else {
104150
FileUtils.forceDeleteOnExit(iconFolder.toFile());
105-
if (!inWindow) {
106-
System.out.println("Icon file created: " + icnsFile);
107-
System.exit(0);
108-
}
151+
System.out.println("Icon file created: " + icnsFile);
152+
System.exit(0);
109153
response.set(true, "");
110154
}
111155
}
112156
else {
113157
msg = "Could not create the icon workspace folder, permission issue?";
114-
response.set(false, msg);
115-
if (!inWindow) {
116-
System.out.println(msg);
117-
System.exit(0);
118-
}
158+
System.out.println(msg);
159+
System.exit(0);
119160
}
120-
} catch (IOException e) {
121-
System.err.println("There was an error. If the following information does not help you figure out the problem, copy and paste the text below the line and create an issue on https://github.com/EasyG0ing1/MacIcns\n---------------------------------------------------------------\nProcessFile.processFile()\n\n");
122-
throw new RuntimeException(e);
123-
}
124-
}
125-
return response;
126-
}
127-
128-
private static class Job {
129-
public Job(Image original, Path path, int size) {
130-
this.original = original;
131-
this.path = path;
132-
this.size = size;
133-
}
134-
135-
public static WritableImage lastImage;
136-
private final Image original;
137-
private final Path path;
138-
private final int size;
139-
private int lastSize = 0;
140-
141-
public void saveFile() {
142-
try {
143-
PNGJavaFXUtils.writeImage(getImage(), path);
144-
} catch (IOException e) {
145-
throw new RuntimeException(e);
146161
}
147-
}
148-
149-
private WritableImage getImage() {
150-
try {
151-
WritableImage writableImage;
152-
if(lastImage == null) {
153-
writableImage = resizeImage(original, size, size);
154-
lastImage = writableImage;
155-
lastSize = size;
156-
}
157-
else {
158-
if(size == lastSize) {
159-
writableImage = lastImage;
160-
}
161-
else {
162-
writableImage = resizeImage(lastImage, size, size);
163-
lastSize = size;
164-
}
165-
}
166-
return writableImage;
167-
} catch (Exception e) {
162+
catch (IOException e) {
163+
System.err.println("There was an error. If the following information does not help you figure out the problem, copy and paste the text below the line and create an issue on https://github.com/EasyG0ing1/MacIcns\n---------------------------------------------------------------\nProcessFile.processFileShell()\n\n");
168164
throw new RuntimeException(e);
169165
}
170166
}
171-
172-
private WritableImage resizeImage(Image originalImage, int targetWidth, int targetHeight) {
173-
int width = (int) originalImage.getWidth();
174-
int height = (int) originalImage.getHeight();
175-
176-
WritableImage resizedImage = new WritableImage(targetWidth, targetHeight);
177-
for (int x = 0; x < targetWidth; x++) {
178-
for (int y = 0; y < targetHeight; y++) {
179-
double sourceX = x * width / (double) targetWidth;
180-
double sourceY = y * height / (double) targetHeight;
181-
Color color = originalImage.getPixelReader().getColor((int) sourceX, (int) sourceY);
182-
resizedImage.getPixelWriter().setColor(x, y, color);
183-
}
184-
}
185-
return resizedImage;
186-
}
167+
return response;
187168
}
188169

189170
}

0 commit comments

Comments
 (0)