-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/album api (Refactored) #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
manoger
wants to merge
54
commits into
dev
Choose a base branch
from
feature/album-api
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
39dca18
Functional upload to a directory in the desktop by multipart file POST.
manoger 9359b64
refatoração de metodos e novas configurações em application properties
manoger e63440e
Reformulated the Profile Images's API
manoger 9f3baec
Added Delete Method.
manoger 362c801
Added new Exceptions and alteration in the root images directory.
manoger f55ec29
Removed verifications of user existence.
manoger 7631c72
Added:Image reSizer util
manoger c5abfa8
Alteration: Controller reduced to POST,GET,DELETE
manoger dd832d1
Added: Class intended to do general cool things like tree directories.
manoger 6e2113f
Alteration: Only multiPartFile upload test is working properly for now.
manoger 2371ec6
Alteration: Only multiPartFile upload test is working properly for now.
manoger 49053f3
Alteration: ImageStorer can resize images now!
manoger 5ee2aa5
New exception for 415(NotSupportedMediaType) http response.
manoger 9fadf1a
Added upload size limit.
manoger 7e9621a
new Exception for 413(PayloadTooLarge) http response
manoger 5847d29
Added validation of Image extension
manoger 6620d33
Updated tests
manoger 19b1ba7
Removed user existence validation
manoger ccaecf7
correction in typo
manoger 69d8cbc
Deleted class typo
manoger 6f0a2ce
Added image type validation
manoger fb272e3
removed verifyIfIsPayloadTooLarge and verifyIfHasImageExtension methods
manoger 70c1a15
Scope changes.
manoger 33cb12a
New tests and mocks.
manoger a6ce8ed
Renamed the entire module
manoger d03fa89
Added polymorphism to StoreImageProfile()
manoger dfcdfb5
UtilsController can generate random profile images.
manoger 1afe85f
SetUp for tests with valid image
manoger 6f8f5f4
Added an special user to try the API
manoger e2039dd
Removed the entire module with "Album" as name
manoger c98756b
EOL at EOF
manoger ccb9592
Refactored @RequestMapping
manoger d287db2
EOL at EOF
manoger b6374fb
Switched explicit variable types to var
manoger e282e72
Regex: added "start of line"
manoger 5da3af0
Regex: added "start of line"
manoger 8185cf1
Added spacing between methods
manoger 6a4d617
EOL at EOF
manoger f5d9d13
Comments removed
manoger 54bc130
Alteration on the url for tests
manoger 52bbb2c
Deleted the "hey" test
manoger f5a4353
Import static for asserts
manoger e2b96ee
Deleted test user, method "hey" and "searchSomeImage"
manoger 882455c
added "mugshot"
manoger 74e5bef
Solved bug of pull request
manoger 3930583
Changed path to database file
manoger 81cb2eb
changed @autowired position
manoger 11d2a1a
EOL at EOF
manoger 348a9b4
Increased test coverage
manoger 42e01a1
Added spaces
manoger f7618cf
Added spaces
manoger f149ed0
Added spaces
manoger 871fc9d
Added spaces
manoger d511aff
preparação do ambiente para o novo repositório
fcidade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| buildscript { | ||
| ext { | ||
| springBootVersion = '2.1.3.RELEASE' | ||
| springCloudVersion = 'Greenwich.SR1' | ||
| } | ||
| repositories { | ||
| mavenCentral() | ||
| maven { url 'https://repo.spring.io/milestone' } | ||
| } | ||
| dependencies { | ||
| classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" as Object | ||
| classpath "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" as Object | ||
| } | ||
| } | ||
|
|
||
| plugins { | ||
| id "io.spring.dependency-management" version "1.0.5.RELEASE" | ||
| id 'java' | ||
| id 'org.springframework.boot' version '2.1.3.RELEASE' | ||
| } | ||
|
|
||
| apply plugin: 'io.spring.dependency-management' | ||
|
|
||
| group = 'hive' | ||
| version = '0.0.1-SNAPSHOT' | ||
| sourceCompatibility = '11' | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| maven { url 'https://repo.spring.io/milestone' } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation project(':common') | ||
| implementation project(':entity') | ||
|
|
||
| implementation 'javax.xml.bind:jaxb-api:2.3.1' | ||
| implementation 'javax.activation:activation:1.1.1' | ||
| implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.2' | ||
|
|
||
| implementation 'org.springframework.boot:spring-boot-starter-web' | ||
| implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
| implementation 'com.h2database:h2' | ||
| implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' | ||
| testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
| } | ||
|
|
||
| dependencyManagement { | ||
| imports { | ||
| mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}" | ||
| mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions
15
mugshot/src/main/java/hive/mugshot/MugshotApplication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package hive.mugshot; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import org.springframework.boot.autoconfigure.domain.EntityScan; | ||
| import org.springframework.cloud.netflix.eureka.EnableEurekaClient; | ||
|
|
||
| @SpringBootApplication | ||
| @EnableEurekaClient | ||
| @EntityScan( basePackages = {"hive.entity"} ) | ||
| public class MugshotApplication { | ||
| public static void main(String[] args) { | ||
| SpringApplication.run(MugshotApplication.class, args); | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
mugshot/src/main/java/hive/mugshot/controller/MugshotController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package hive.mugshot.controller; | ||
|
|
||
| import hive.mugshot.exception.NotAcceptedFileFormatException; | ||
| import hive.mugshot.storage.ImageStorer; | ||
| import hive.common.security.HiveHeaders; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
| import org.springframework.core.io.Resource; | ||
|
|
||
| import static hive.mugshot.storage.ImageUtils.validateIfHasAnImageAsExtension; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/") | ||
| public class MugshotController { | ||
|
|
||
| @Value("${hive.mugshot.profile-image-name}") | ||
| private String imageName; | ||
| private final ImageStorer imageStorer; | ||
|
|
||
| @Autowired | ||
| public MugshotController(ImageStorer imageStorer) { | ||
| this.imageStorer = imageStorer; | ||
| } | ||
|
|
||
| @ResponseStatus(code = HttpStatus.OK, reason = "Profile image successfully stored") | ||
| @PostMapping | ||
| public void sendImageProfile( | ||
| @RequestParam("image") MultipartFile insertedImage, | ||
| @RequestHeader(name = HiveHeaders.AUTHENTICATED_USER_ID) final String userId | ||
| ){ | ||
| if(!validateIfHasAnImageAsExtension(insertedImage.getOriginalFilename())) { | ||
| throw new NotAcceptedFileFormatException(); | ||
| } | ||
| imageStorer.storeImageProfile(userId,insertedImage,imageName); | ||
| } | ||
|
|
||
| @GetMapping(produces = MediaType.IMAGE_JPEG_VALUE) | ||
| public ResponseEntity<Resource> searchProfileImage( | ||
| @RequestHeader(name = HiveHeaders.AUTHENTICATED_USER_ID) final String userId | ||
| ){ | ||
| Resource file = imageStorer.loadImage(userId,imageName); | ||
| return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFilename() + "\"").body(file); | ||
| } | ||
|
|
||
| @ResponseStatus(code = HttpStatus.NO_CONTENT, reason = "Profile image successfully deleted") | ||
| @DeleteMapping | ||
| public void deleteProfileImage( | ||
| @RequestHeader(name = HiveHeaders.AUTHENTICATED_USER_ID) final String userId | ||
| ){ | ||
| imageStorer.deleteImage(userId,imageName); | ||
| } | ||
|
|
||
| } |
31 changes: 31 additions & 0 deletions
31
mugshot/src/main/java/hive/mugshot/controller/UtilsController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,31 @@ | ||||||
| package hive.mugshot.controller; | ||||||
|
|
||||||
| import hive.mugshot.storage.ImageStorer; | ||||||
| import hive.mugshot.storage.ImageUtils; | ||||||
| import hive.common.security.HiveHeaders; | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||||
| import org.springframework.beans.factory.annotation.Value; | ||||||
| import org.springframework.http.HttpStatus; | ||||||
| import org.springframework.web.bind.annotation.*; | ||||||
|
|
||||||
| @RestController | ||||||
| @RequestMapping("/utils") | ||||||
| public class UtilsController { | ||||||
|
|
||||||
| private final ImageStorer imageStorer; | ||||||
| @Value("${hive.mugshot.profile-image-name}") | ||||||
| private String imageName; | ||||||
|
|
||||||
| @Autowired | ||||||
| public UtilsController(ImageStorer imageStorer){ | ||||||
| this.imageStorer=imageStorer; | ||||||
| } | ||||||
|
|
||||||
| @ResponseStatus(code = HttpStatus.OK, reason = "Random image generated and successfully stored") | ||||||
| @PostMapping("/generateRandomImage") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| public void generateRandomImage(@RequestHeader(name = HiveHeaders.AUTHENTICATED_USER_ID) final String userId) { | ||||||
| var generatedImage=ImageUtils.generateRandomImage(); | ||||||
| imageStorer.storeImageProfile(userId,generatedImage,imageName); | ||||||
| } | ||||||
|
|
||||||
| } | ||||||
7 changes: 7 additions & 0 deletions
7
mugshot/src/main/java/hive/mugshot/exception/FileSizeException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package hive.mugshot.exception; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
|
||
| @ResponseStatus(code = HttpStatus.PAYLOAD_TOO_LARGE,reason = "Invalid size of file") | ||
| public class FileSizeException extends RuntimeException{ | ||
| } |
7 changes: 7 additions & 0 deletions
7
mugshot/src/main/java/hive/mugshot/exception/ImageAlreadyExistException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package hive.mugshot.exception; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
|
||
| @ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "The Image already exists") | ||
| public class ImageAlreadyExistException extends RuntimeException{ | ||
| } |
7 changes: 7 additions & 0 deletions
7
mugshot/src/main/java/hive/mugshot/exception/ImageNotFound.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package hive.mugshot.exception; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
|
||
| @ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "Image not found for this user") | ||
| public class ImageNotFound extends RuntimeException{ | ||
| } |
7 changes: 7 additions & 0 deletions
7
mugshot/src/main/java/hive/mugshot/exception/ImageProfileException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package hive.mugshot.exception; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
|
||
| @ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "Failed to store the image due to some I/O problem or permission") | ||
| public class ImageProfileException extends RuntimeException{ | ||
| } |
8 changes: 8 additions & 0 deletions
8
mugshot/src/main/java/hive/mugshot/exception/InvalidPathException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package hive.mugshot.exception; | ||
|
|
||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
|
||
| @ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "Invalid path") | ||
| public class InvalidPathException extends RuntimeException { | ||
| } |
7 changes: 7 additions & 0 deletions
7
mugshot/src/main/java/hive/mugshot/exception/NotAcceptedFileFormatException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package hive.mugshot.exception; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
|
||
| @ResponseStatus(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE, reason = "Media type unsupported") | ||
| public class NotAcceptedFileFormatException extends RuntimeException{ | ||
| } |
8 changes: 8 additions & 0 deletions
8
mugshot/src/main/java/hive/mugshot/exception/UserNotFoundException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package hive.mugshot.exception; | ||
|
|
||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
|
||
| @ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "The user does not exist") | ||
| public class UserNotFoundException extends RuntimeException { | ||
| } |
8 changes: 8 additions & 0 deletions
8
mugshot/src/main/java/hive/mugshot/repository/UserRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package hive.mugshot.repository; | ||
|
|
||
| import hive.entity.user.User; | ||
| import org.springframework.data.repository.CrudRepository; | ||
|
|
||
| public interface UserRepository extends CrudRepository<User, Integer> { | ||
| User findByUsername(String username); | ||
| } |
83 changes: 83 additions & 0 deletions
83
mugshot/src/main/java/hive/mugshot/storage/ImageStorer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package hive.mugshot.storage; | ||
|
|
||
| import hive.mugshot.exception.*; | ||
| import hive.mugshot.exception.InvalidPathException; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.core.io.Resource; | ||
| import org.springframework.core.io.UrlResource; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| import javax.imageio.ImageIO; | ||
| import java.awt.image.BufferedImage; | ||
| import java.io.IOException; | ||
| import java.net.MalformedURLException; | ||
| import java.nio.file.*; | ||
|
|
||
| @Service | ||
| public class ImageStorer { | ||
| @Value("${hive.mugshot.image-directory-path}") | ||
| private String rootDir; | ||
| @Value("${hive.mugshot.profile-image-dimension}") | ||
| private int imageSizeInPixels; | ||
|
|
||
| public void storeImageProfile(String userDirectoryName, MultipartFile insertedImage, String imageStoredName){ | ||
| createDirectoryIfNotExist(userDirectoryName); | ||
| try { | ||
| var buff = ImageUtils.resizeImageToSquare(ImageIO.read(insertedImage.getInputStream()),imageSizeInPixels); | ||
| ImageIO.write(buff, "jpg", createFullPathToTheFile(userDirectoryName, imageStoredName).toFile()); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| public void storeImageProfile(String userDirectoryName, BufferedImage insertedImage, String imageStoredName){ | ||
| createDirectoryIfNotExist(userDirectoryName); | ||
| try { | ||
| var buff = ImageUtils.resizeImageToSquare(insertedImage,imageSizeInPixels); | ||
| ImageIO.write(buff, "jpg", createFullPathToTheFile(userDirectoryName, imageStoredName).toFile()); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| public Resource loadImage(String userDirectoryName,String imageName) { | ||
| try { | ||
| var file = createFullPathToTheFile(userDirectoryName,imageName); | ||
| var resource = new UrlResource(file.toUri()); | ||
| if (resource.exists() || resource.isReadable()) { | ||
| return resource; | ||
| }else{ | ||
| throw new ImageNotFound(); | ||
| } | ||
| } catch (MalformedURLException e) { | ||
| e.printStackTrace(); | ||
| throw new InvalidPathException(); | ||
| } | ||
| } | ||
|
|
||
| public void deleteImage(String userDirectoryName, String imageName) { | ||
| var parentDir = createFullPathToTheFile(userDirectoryName,imageName); | ||
| try { | ||
| Files.deleteIfExists(parentDir); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| throw new RuntimeException("Unable to delete the directory.\n"+e); | ||
| } | ||
| } | ||
|
|
||
| private void createDirectoryIfNotExist(String userDirectoryPath){ | ||
| Path parentDir = Paths.get(rootDir,userDirectoryPath); | ||
| if (!Files.exists(parentDir)) { | ||
| try { | ||
| Files.createDirectories(parentDir); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException("Unable to create the directory.\n"+e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private Path createFullPathToTheFile(String userDirectoryName, String filename) { | ||
| return Paths.get(rootDir).resolve(userDirectoryName).resolve(filename); | ||
| } | ||
|
|
||
| } |
65 changes: 65 additions & 0 deletions
65
mugshot/src/main/java/hive/mugshot/storage/ImageUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package hive.mugshot.storage; | ||
|
|
||
| import java.awt.*; | ||
| import java.awt.image.BufferedImage; | ||
| import java.util.Random; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public final class ImageUtils { | ||
| private static final String IMAGE_PATTERN = "(^.+\\.(gif|png|bmp|jpeg|jpg)$)"; | ||
|
|
||
| private ImageUtils(){ | ||
| } | ||
|
|
||
| public static boolean validateIfHasAnImageAsExtension(final String image){ | ||
| var pattern = Pattern.compile(IMAGE_PATTERN); | ||
| var matcher = pattern.matcher(image); | ||
| return matcher.matches(); | ||
| } | ||
|
|
||
| public static BufferedImage resizeImageToSquare(BufferedImage inputtedImage,int imageSizeInPixels) { | ||
| // multi-pass bilinear div 2 | ||
| var bufferedImageWithNewSize = new BufferedImage(imageSizeInPixels, imageSizeInPixels, BufferedImage.TYPE_INT_RGB); | ||
| var reSizer = bufferedImageWithNewSize.createGraphics(); | ||
| var resizingMode= | ||
| (inputtedImage.getHeight()<imageSizeInPixels) | ||
| ? RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR | ||
| : RenderingHints.VALUE_INTERPOLATION_BILINEAR; | ||
| reSizer.setRenderingHint(RenderingHints.KEY_INTERPOLATION, resizingMode); | ||
| reSizer.drawImage(inputtedImage, 0, 0, imageSizeInPixels, imageSizeInPixels, null); | ||
| reSizer.dispose(); | ||
| return bufferedImageWithNewSize; | ||
| } | ||
|
|
||
| public static BufferedImage generateRandomImage(){ | ||
| var yellow=0xF6BD60; | ||
| var orange=0xE9724C; | ||
| var gray = 0xE8E9EB; | ||
| var blue = 0x5C9EAD; | ||
| var black = 0x313638; | ||
| var colorsCombinations=new int[][]{ | ||
| {yellow,black}, | ||
| {orange,black}, | ||
| {blue,black}, | ||
| {blue,gray}, | ||
| {orange,yellow} | ||
| }; | ||
| var combinationIndex=new Random().nextInt(colorsCombinations.length); | ||
| var img=new BufferedImage(9,9,BufferedImage.TYPE_INT_RGB); | ||
| var maxH=img.getHeight(); | ||
| var maxV=img.getWidth(); | ||
| for(int vertical=0;vertical<maxV;vertical++){ | ||
| for(int horizontal=0;horizontal<maxH;horizontal++){ | ||
| var pixel=0; | ||
| if(Math.random()<0.7){ | ||
| pixel=colorsCombinations[combinationIndex][0]; | ||
| }else{ | ||
| pixel=colorsCombinations[combinationIndex][1]; | ||
| } | ||
| img.setRGB(horizontal,vertical,pixel); | ||
| } | ||
| } | ||
| return img; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nop, success isn't Exception