Skip to content

Commit

Permalink
Make resizing optional
Browse files Browse the repository at this point in the history
  • Loading branch information
making committed Jun 6, 2024
1 parent d5da39e commit c28e529
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/am/ik/blog/image/ImageProxyProps.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.springframework.validation.Validator;

@ConfigurationProperties(prefix = "image-proxy")
public record ImageProxyProps(@DefaultValue("22") int compressionLevel, @DefaultValue("1024") int maxWidth,
@DefaultValue("/tmp/image-proxy") Path storePath) implements Validator {
public record ImageProxyProps(@DefaultValue("22") int compressionLevel, @DefaultValue("false") boolean resizeEnabled,
@DefaultValue("1024") int maxWidth, @DefaultValue("/tmp/image-proxy") Path storePath) implements Validator {
@Override
public boolean supports(Class<?> clazz) {
return clazz == ImageProxyProps.class;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/am/ik/blog/image/ImageStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ Image compute(String path, Supplier<Image> imageDownloader) {
}
}
Image downloaded = imageDownloader.get();
Image image = ImageBuilder.from(downloaded).body(downloaded.resize(this.proxyProps.maxWidth())).build();
Image image = this.proxyProps.resizeEnabled()
? ImageBuilder.from(downloaded).body(downloaded.resize(this.proxyProps.maxWidth())).build()
: downloaded;
logger.info("op=store base=\"{}\"", base);
Files.write(raw, Objects.requireNonNull(image.body()), StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
Expand Down

0 comments on commit c28e529

Please sign in to comment.