Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/groovy/infra/images/BasicImageManager.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class BasicImageManager implements ImageManager {
@Override
ImageInfo getInfo(ImageFormat format) {
if (format instanceof CustomFormat) {
format.baseFormat = imageBundle.basesFormat
format.baseFormat = imageBundle.baseFormat
}
new ImageInfo(format, getSize(format), getSrc(format))
}
Expand Down Expand Up @@ -110,7 +110,7 @@ class BasicImageManager implements ImageManager {
void reformat(ImageFormat format) {
if (!isStored()) return;
if (format instanceof CustomFormat) {
format.baseFormat = imageBundle.basesFormat
format.baseFormat = imageBundle.baseFormat
}
loadOriginal()
if (originalImage.file?.exists()) {
Expand Down Expand Up @@ -168,7 +168,7 @@ class BasicImageManager implements ImageManager {
@Override
String getSrc(ImageFormat format) {
if (format instanceof CustomFormat) {
format.setBaseFormat(imageBundle.basesFormat)
format.setBaseFormat(imageBundle.baseFormat)
if (!filesManager.exists(getFilename(format))) {
loadOriginal()
ImageBox box = imageFormatter.format(format, originalImage)
Expand Down
4 changes: 1 addition & 3 deletions src/java/infra/images/util/ImageBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public File getFile() {
public ImageSize getSize() {
if (size == null) {
try {
size = ImageSize.buildReal(
getBuffered().getWidth(),
getBuffered().getHeight());
size = ImageSize.extract(getBuffered());
} catch (IOException e) {
size = new ImageSize(0, 0, 0f);
}
Expand Down
50 changes: 30 additions & 20 deletions src/java/infra/images/util/ImageCropPolicy.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,59 @@
package infra.images.util;

import java.util.EnumSet;

/**
* @author Dmitry Kurinskiy
* @since 21.10.11 14:58
*/
public enum ImageCropPolicy {
DEFAULT(15),
NONE(0),
TOP_LEFT(5),
TOP_CENTER(7),
TOP_RIGHT(6),
CENTER_LEFT(13),
CENTER_RIGHT(14),
CENTER(15),
BOTTOM_LEFT(9),
BOTTOM_RIGHT(10),
BOTTOM_CENTER(11);
DEFAULT(EnumSet.of(CropSide.DEFAULT)),
NONE(EnumSet.noneOf(CropSide.class)),
TOP_LEFT(EnumSet.of(CropSide.TOP, CropSide.LEFT)),
TOP_CENTER(EnumSet.of(CropSide.TOP)),
TOP_RIGHT(EnumSet.of(CropSide.TOP, CropSide.RIGHT)),
CENTER_LEFT(EnumSet.of(CropSide.LEFT)),
CENTER_RIGHT(EnumSet.of(CropSide.RIGHT)),
CENTER(EnumSet.of(CropSide.DEFAULT)),
BOTTOM_LEFT(EnumSet.of(CropSide.BOTTOM, CropSide.LEFT)),
BOTTOM_RIGHT(EnumSet.of(CropSide.BOTTOM, CropSide.RIGHT)),
BOTTOM_CENTER(EnumSet.of(CropSide.BOTTOM));

private enum CropSide {
TOP, RIGHT, BOTTOM, LEFT, DEFAULT // css order
}

private byte policy;
private final EnumSet<CropSide> cropSides;

ImageCropPolicy(int policy) {
this.policy = (byte) policy;
ImageCropPolicy(EnumSet<CropSide> cropSides) {
this.cropSides = cropSides;
}

public boolean isDefault() {
return policy == 15;
return cropSides.contains(CropSide.DEFAULT);
}

public boolean isNoCrop() {
return policy == 0;
return cropSides.isEmpty();
}

public boolean isAny() {
return !cropSides.isEmpty();
}

public boolean isTop() {
return (policy & 12) == 4;
return cropSides.contains(CropSide.TOP);
}

public boolean isBottom() {
return (policy & 12) == 8;
return cropSides.contains(CropSide.BOTTOM);
}

public boolean isLeft() {
return (policy & 3) == 1;
return cropSides.contains(CropSide.LEFT);
}

public boolean isRight() {
return (policy & 3) == 2;
return cropSides.contains(CropSide.RIGHT);
}
}
12 changes: 6 additions & 6 deletions src/java/infra/images/util/ImageFormatsBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
*/
public class ImageFormatsBundle {
private final Map<String, ImageFormat> formats;
private final ImageFormat basesFormat;
private final ImageFormat baseFormat;
private final String name;
private final ImageFormat original;
private Integer version;

public ImageFormatsBundle(String name, Map<String, ImageFormat> formats, ImageFormat basesFormat) {
public ImageFormatsBundle(String name, Map<String, ImageFormat> formats, ImageFormat baseFormat) {
this.name = name;
this.basesFormat = basesFormat;
this.original = new OriginalFormat(this.name, this.basesFormat);
this.baseFormat = baseFormat;
this.original = new OriginalFormat(this.name, this.baseFormat);
formats.put(name, this.original);
this.formats = formats;
}
Expand All @@ -28,8 +28,8 @@ public Map<String, ImageFormat> getFormats() {
return formats;
}

public ImageFormat getBasesFormat() {
return basesFormat;
public ImageFormat getBaseFormat() {
return baseFormat;
}

public String getName() {
Expand Down
6 changes: 6 additions & 0 deletions src/java/infra/images/util/ImageSize.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package infra.images.util;

import java.awt.image.BufferedImage;

/**
* Wraps image size and density
*
Expand All @@ -12,6 +14,10 @@ public class ImageSize {
final float density;
final String name;

static public ImageSize extract(BufferedImage image) {
return new ImageSize(image.getWidth(), image.getHeight(), 1f);
}

static public ImageSize buildReal(int realWidth, int realHeight) {
return new ImageSize(realWidth, realHeight, 1f);
}
Expand Down