Skip to content

Commit

Permalink
add maven support. Docker still TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
lr101 committed Dec 12, 2023
1 parent 35d826b commit 58dc727
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 106 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM openjdk:17-jdk-slim AS build

COPY pom.xml mvnw ./
COPY .mvn .mvn
RUN ./mvnw dependency:resolve

COPY src src
RUN ./mvnw package

FROM openjdk:17-jdk-slim
WORKDIR demo
COPY --from=build target/*.jar demo.jar
ENTRYPOINT ["java", "-jar", "picturecollage-1.jar"]
23 changes: 22 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,26 @@
<url>https://maven.pkg.github.com/lr101/PictureCollage</url>
</repository>
</distributionManagement>


<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>


</project>
1 change: 0 additions & 1 deletion src/main/java/Coordinate.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package main.java;

public record Coordinate(int xC, int yC) {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/DefaultShape.java
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package main.java;import java.awt.*;import java.awt.image.BufferedImage;import java.io.IOException;import java.util.ArrayList;public abstract class DefaultShape { int HEX_COLOR = 0x000000; abstract ArrayList<Image> getCoordinates(Dimension borderD, ArrayList<Image> images) throws IOException; abstract Dimension getFinalPictureSize(int numImages, int rows, int width); abstract Boolean[][] createShapeMap(Image image, double size); abstract double getSize(); public void writeShape(Dimension d, Graphics2D g, Image image, Boolean[][] map) throws IOException { if (image != null) { int width = image.getWidth(); int height = image.getHeight(); int xC = image.getLeftTop().xC(); int yC = image.getLeftTop().yC(); BufferedImage bufI = image.getImage(); for (int x = 0; x < width; x++){ for (int y = 0; y < height; y++) { if (map[x][y]) { int xCor = xC + x; int yCor = yC + y; g.drawImage(bufI, xCor, yCor, xCor + 1, yCor + 1,x, y, x +1, y + 1, null); } } } bufI.flush(); } }}
import java.awt.*;import java.awt.image.BufferedImage;import java.io.IOException;import java.util.ArrayList;public abstract class DefaultShape { int HEX_COLOR = 0x000000; abstract ArrayList<Image> getCoordinates(Dimension borderD, ArrayList<Image> images) throws IOException; abstract Dimension getFinalPictureSize(int numImages, int rows, int width); abstract Boolean[][] createShapeMap(Image image, double size); abstract double getSize(); public void writeShape(Dimension d, Graphics2D g, Image image, Boolean[][] map) throws IOException { if (image != null) { int width = image.getWidth(); int height = image.getHeight(); int xC = image.getLeftTop().xC(); int yC = image.getLeftTop().yC(); BufferedImage bufI = image.getImage(); for (int x = 0; x < width; x++){ for (int y = 0; y < height; y++) { if (map[x][y]) { int xCor = xC + x; int yCor = yC + y; g.drawImage(bufI, xCor, yCor, xCor + 1, yCor + 1,x, y, x +1, y + 1, null); } } } bufI.flush(); } }}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/Dimension.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package main.java;

public class Dimension {

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/Hexagon.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
package main.java;

import main.java.Coordinate;
import main.java.DefaultShape;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
Expand Down Expand Up @@ -184,4 +179,9 @@ public void writeShape(Dimension d, Graphics2D g, Image image, Boolean[][] map)
bufI.flush();
}
}

@Override
public String toString() {
return "Hexagon";
}
}
4 changes: 0 additions & 4 deletions src/main/java/Image.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
package main.java;

import main.java.Coordinate;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.FileImageInputStream;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/ImageManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
package main.java;

import main.java.DefaultShape;

import javax.imageio.ImageIO;
import java.awt.*;
Expand Down
94 changes: 17 additions & 77 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,99 +1,39 @@
package main.java;

import java.awt.*;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
import java.util.Scanner;

public class Main {

private static String PICTURES_DIR;
private static String SAVED_TO_DIR;
public static DefaultShape SELECTED_SHAPE;
public static int WIDTH;
public static int HEIGHT;
public static String FILE_NAME;

public static void main(String[] args) {
print("Collage created BY [email protected]\n");
Scanner scanner = new Scanner(System.in);
File path = new File("C");

while(!path.isDirectory()){
print("Type the path to directory of the images you choose to use: ");
path = new File(scanner.nextLine());
PICTURES_DIR = path.getAbsolutePath();
SAVED_TO_DIR = PICTURES_DIR;
}
File path = new File(System.getenv("IMAGES_PATH"));
String picturesDir = path.getAbsolutePath();
SELECTED_SHAPE = System.getenv("SHAPE").equals("Hexagon") ? new Hexagon() : new Rectangle();
WIDTH = Integer.parseInt(System.getenv("WIDTH"));
HEIGHT = Integer.parseInt(System.getenv("HEIGHT"));

FILE_NAME = new SimpleDateFormat("yyyyMMddHHmm'_collage'").format(new Date());

print("Collage created BY [email protected]\n");
print("Used directory: " + picturesDir);
print("Used shape:" + SELECTED_SHAPE.toString());
print("Used width:" + WIDTH);
print("Used Height: " + HEIGHT + " " + (SELECTED_SHAPE instanceof Hexagon ? "rows" : "pixel"));
print("Saving into: " + FILE_NAME);


boolean test = true;
print("Choose your shape (0: Rectangle | 1: Hexagon): ");
while(test){
if (scanner.hasNextInt()){
int i = scanner.nextInt();
if (i == 0) {
SELECTED_SHAPE = new Rectangle();
test = false;
} else if (i == 1) {
SELECTED_SHAPE = new Hexagon();
test = false;
} else {
scanner.next();
print("Choose your shape (0: Rectangle | 1: Hexagon): ");
}
}else {
scanner.next();
print("Choose your shape (0: Rectangle | 1: Hexagon: ");
}
}

test = true;
print("Width (in pixel): ");
while(test){
if (scanner.hasNextInt()){
WIDTH = scanner.nextInt();
test = false;
}else {
scanner.next();
print("Width (in pixel): ");
}
}


test = true;
print("Height (" + (SELECTED_SHAPE instanceof Hexagon ? "in rows" : "in pixel") + "): ");
while(test){
if (scanner.hasNextInt()){
HEIGHT = scanner.nextInt();
test = false;
}else {
scanner.next();
print("Height (in pixel): ");
}
}

test = true;
print("Name of final image: ");
while(test){
if (scanner.hasNext()){
FILE_NAME = scanner.next();
test = false;
}else {
scanner.next();
print("Name of final image: ");
}
}

scanner.close();
ShapeManagement m;
int numImages = Objects.requireNonNull(new File(PICTURES_DIR).list((dir, name) -> (name.toLowerCase().endsWith(".jpg") || name.toLowerCase().endsWith(".jpeg") || name.toLowerCase().endsWith(".png")))).length;
int numImages = Objects.requireNonNull(new File(picturesDir).list((dir, name) -> (name.toLowerCase().endsWith(".jpg") || name.toLowerCase().endsWith(".jpeg") || name.toLowerCase().endsWith(".png")))).length;
if (SELECTED_SHAPE instanceof Hexagon) {
m = new ShapeManagement(new File(PICTURES_DIR), SELECTED_SHAPE, new File(SAVED_TO_DIR), HEIGHT, WIDTH, numImages);
m = new ShapeManagement(new File(picturesDir), SELECTED_SHAPE, new File(picturesDir), HEIGHT, WIDTH, numImages);
} else {
m = new ShapeManagement(new File(PICTURES_DIR), SELECTED_SHAPE, new File(SAVED_TO_DIR), new Dimension(WIDTH, HEIGHT));
m = new ShapeManagement(new File(picturesDir), SELECTED_SHAPE, new File(picturesDir), new Dimension(WIDTH, HEIGHT));
}
m.run(FILE_NAME);

Expand Down
12 changes: 5 additions & 7 deletions src/main/java/Rectangle.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
package main.java;

import main.java.Coordinate;
import main.java.DefaultShape;
import main.java.Dimension;
import main.java.Image;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -136,4 +129,9 @@ public Boolean[][] createShapeMap(Image image, double size) {
public double getSize() {
return -1;
}

@Override
public String toString() {
return "Rectangle";
}
}
2 changes: 1 addition & 1 deletion src/main/java/RectanglePair.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java;


public class RectanglePair {
private Image rec1;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/ShapeManagement.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
package main.java;

import main.java.DefaultShape;
import main.java.ImageManager;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
Expand Down

0 comments on commit 58dc727

Please sign in to comment.