Skip to content

Commit

Permalink
StitchTool v4.0.2
Browse files Browse the repository at this point in the history
Fixed watermarking.
  • Loading branch information
Aeonss committed Mar 30, 2022
1 parent a765495 commit c7953e5
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 31 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Project exclude paths
/out/
/.idea/
/.idea/
/jdeploy/
/jdeploy-bundle/
*.json
*.jar
*.iml
*.xml
46 changes: 36 additions & 10 deletions src/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -750,16 +750,9 @@ public void onWatermark() throws IOException {
if (greyOption.isSelected()) {
ImageFilter imageFilter = new GrayFilter(true, 5);
ImageProducer producer = new FilteredImageSource(watermark.getSource(), imageFilter);
watermark = (BufferedImage) Toolkit.getDefaultToolkit().createImage(producer);
watermark = Util.toBufferedImage(Toolkit.getDefaultToolkit().createImage(producer));
}

// Rescales the image
double ratio = (double) watermark.getWidth() / watermark.getHeight();
Image tempImage = watermark.getScaledInstance(image.getWidth() / 5,
(int)(image.getWidth() / 5 * ratio), Image.SCALE_DEFAULT);

watermark = (BufferedImage) tempImage;

// Asks how many times the watermark will show up
TextInputDialog input = new TextInputDialog();
input.setHeaderText(null);
Expand All @@ -777,7 +770,33 @@ public void onWatermark() throws IOException {
} catch (NumberFormatException nfe) {
Alert a = new Alert(Alert.AlertType.ERROR);
a.setHeaderText(null);
a.setContentText("Please input a number only!");
a.setContentText("Please input a number that is more than 0!");
a.showAndWait();
input.showAndWait();
if (input.getResult() == null) {
return;
}
}
}

// Asks how % of width the watermark
TextInputDialog inputSize = new TextInputDialog();
inputSize.setHeaderText(null);
inputSize.setContentText("What % of width would you like the watermark to be?");
inputSize.showAndWait();
if (inputSize.getResult() == null) {
return;
}

// Makes sure the input is a number
int width = 0;
while (width <= 0 || width > 100) {
try {
width = Integer.parseInt(inputSize.getResult());
} catch (NumberFormatException nfe) {
Alert a = new Alert(Alert.AlertType.ERROR);
a.setHeaderText(null);
a.setContentText("Please input a percentage between 1 and 100!");
a.showAndWait();
input.showAndWait();
if (input.getResult() == null) {
Expand All @@ -786,6 +805,13 @@ public void onWatermark() throws IOException {
}
}

// Rescales the image
double ratio = (double) watermark.getWidth() / watermark.getHeight();
Image tempImage = watermark.getScaledInstance(image.getWidth() * width/100,
(int)(image.getWidth() * width/100 * ratio), Image.SCALE_DEFAULT);

watermark = Util.toBufferedImage(tempImage);

// Loop to draw the watermark
Graphics2D g = image.createGraphics();
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)opacitySlider.getValue() / 100));
Expand All @@ -798,7 +824,7 @@ public void onWatermark() throws IOException {

// Checks if the image has a name
if (nameField.getText().isEmpty()) {
nameField.setText(imageFile.getName() + "_watermarked");
nameField.setText(imageFile.getName().replaceFirst("[.][^.]+$", "") + "_watermarked");
}

// Exports the image
Expand Down
3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Main

2 changes: 1 addition & 1 deletion src/Stitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.Properties;

public class Stitch extends Application {
private final String version = "3.3.8";
private final String version = "4.0.2";

public static void main(String[] args) {
launch(args);
Expand Down
17 changes: 17 additions & 0 deletions src/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,21 @@ public static int askSplitImages() {
}
}

// Converts Image to BufferedImage
public static BufferedImage toBufferedImage(Image img) {
if (img instanceof BufferedImage) {
return (BufferedImage) img;
}

// Create a buffered image with transparency
BufferedImage image = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);

// Draw the image on to the buffered image
Graphics2D bGr = image.createGraphics();
bGr.drawImage(img, 0, 0, null);
bGr.dispose();

return image;
}

}
Binary file removed target/Stitch-1.0-SNAPSHOT.jar
Binary file not shown.
Binary file modified target/classes/Controller.class
Binary file not shown.
Binary file modified target/classes/Stitch.class
Binary file not shown.
Binary file modified target/classes/Util.class
Binary file not shown.
5 changes: 0 additions & 5 deletions target/maven-archiver/pom.properties

This file was deleted.

This file was deleted.

This file was deleted.

Binary file removed target/original-Stitch-1.0-SNAPSHOT.jar
Binary file not shown.

0 comments on commit c7953e5

Please sign in to comment.