Skip to content
Merged
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
Binary file modified dist/ImageCrop.mpk
Binary file not shown.
Binary file modified src_module/ImageCrop.mpr
Binary file not shown.
15 changes: 9 additions & 6 deletions src_module/javasource/imagecrop/actions/CopyFileContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
import com.mendix.systemwideinterfaces.core.IMendixObject;
import com.mendix.webui.CustomJavaAction;

public class CopyFileContent extends CustomJavaAction<java.lang.Boolean>
/**
*
*/
public class CopyFileContent extends CustomJavaAction<Boolean>
{
private IMendixObject OriginalFile;
private IMendixObject TargetFile;
private java.lang.Long thumbWidth;
private java.lang.Long thumbHeight;
private Long thumbWidth;
private Long thumbHeight;

public CopyFileContent(IContext context, IMendixObject OriginalFile, IMendixObject TargetFile, java.lang.Long thumbWidth, java.lang.Long thumbHeight)
public CopyFileContent(IContext context, IMendixObject OriginalFile, IMendixObject TargetFile, Long thumbWidth, Long thumbHeight)
{
super(context);
this.OriginalFile = OriginalFile;
Expand All @@ -31,7 +34,7 @@ public CopyFileContent(IContext context, IMendixObject OriginalFile, IMendixObje
}

@Override
public java.lang.Boolean executeAction() throws Exception
public Boolean executeAction() throws Exception
{
// BEGIN USER CODE
Core.storeImageDocumentContent(getContext(), this.TargetFile, Core.getFileDocumentContent(getContext(), this.OriginalFile), this.thumbWidth.intValue(), this.thumbHeight.intValue());
Expand All @@ -44,7 +47,7 @@ public java.lang.Boolean executeAction() throws Exception
* Returns a string representation of this action
*/
@Override
public java.lang.String toString()
public String toString()
{
return "CopyFileContent";
}
Expand Down
19 changes: 12 additions & 7 deletions src_module/javasource/imagecrop/actions/CreateBWImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,35 @@
import com.mendix.webui.CustomJavaAction;
import imagecrop.implementation.ImageUtil;

public class CreateBWImage extends CustomJavaAction<java.lang.Boolean>
/**
*
*/
public class CreateBWImage extends CustomJavaAction<Boolean>
{
private IMendixObject ColorImage;
private IMendixObject BWImage;
private java.lang.Long thumbnailWidth;
private java.lang.Long thumbnailHeight;
private Long thumbnailWidth;
private Long thumbnailHeight;
private java.math.BigDecimal jpegCompressionQuality;

public CreateBWImage(IContext context, IMendixObject ColorImage, IMendixObject BWImage, java.lang.Long thumbnailWidth, java.lang.Long thumbnailHeight)
public CreateBWImage(IContext context, IMendixObject ColorImage, IMendixObject BWImage, Long thumbnailWidth, Long thumbnailHeight, java.math.BigDecimal jpegCompressionQuality)
{
super(context);
this.ColorImage = ColorImage;
this.BWImage = BWImage;
this.thumbnailWidth = thumbnailWidth;
this.thumbnailHeight = thumbnailHeight;
this.jpegCompressionQuality = jpegCompressionQuality;
}

@Override
public java.lang.Boolean executeAction() throws Exception
public Boolean executeAction() throws Exception
{
// BEGIN USER CODE
InputStream is = null;
InputStream stream = null;
try {
ImageUtil.processImageBW(this.getContext(), BWImage, ColorImage, thumbnailWidth.intValue(), thumbnailHeight.intValue());
ImageUtil.processImageBW(this.getContext(), BWImage, ColorImage, thumbnailWidth.intValue(), thumbnailHeight.intValue(), jpegCompressionQuality.floatValue());
}
catch (IOException e) {
Core.getLogger(this.toString()).error(e);
Expand All @@ -59,7 +64,7 @@ public java.lang.Boolean executeAction() throws Exception
* Returns a string representation of this action
*/
@Override
public java.lang.String toString()
public String toString()
{
return "CreateBWImage";
}
Expand Down
25 changes: 16 additions & 9 deletions src_module/javasource/imagecrop/actions/CropImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,32 @@
import com.mendix.webui.CustomJavaAction;
import imagecrop.implementation.ImageUtil;

public class CropImage extends CustomJavaAction<java.lang.Boolean>
/**
*
*/
public class CropImage extends CustomJavaAction<Boolean>
{
private IMendixObject __cropImgObj;
private imagecrop.proxies.CropImage cropImgObj;
private java.lang.Long imageWidth;
private java.lang.Long imageHeight;
private java.lang.Long thumbnailWidth;
private java.lang.Long thumbnailHeight;
private Long imageWidth;
private Long imageHeight;
private Long thumbnailWidth;
private Long thumbnailHeight;
private java.math.BigDecimal jpegCompressionQuality;

public CropImage(IContext context, IMendixObject cropImgObj, java.lang.Long imageWidth, java.lang.Long imageHeight, java.lang.Long thumbnailWidth, java.lang.Long thumbnailHeight)
public CropImage(IContext context, IMendixObject cropImgObj, Long imageWidth, Long imageHeight, Long thumbnailWidth, Long thumbnailHeight, java.math.BigDecimal jpegCompressionQuality)
{
super(context);
this.__cropImgObj = cropImgObj;
this.imageWidth = imageWidth;
this.imageHeight = imageHeight;
this.thumbnailWidth = thumbnailWidth;
this.thumbnailHeight = thumbnailHeight;
this.jpegCompressionQuality = jpegCompressionQuality;
}

@Override
public java.lang.Boolean executeAction() throws Exception
public Boolean executeAction() throws Exception
{
this.cropImgObj = __cropImgObj == null ? null : imagecrop.proxies.CropImage.initialize(getContext(), __cropImgObj);

Expand All @@ -59,7 +64,9 @@ public java.lang.Boolean executeAction() throws Exception
cropWidth = Math.round(this.cropImgObj.getcrop_width() * ratio);
}

ImageUtil.processImage(this.getContext(), cropImgObj.getMendixObject(), cropWidth, cropHeight, thumbnailWidth.intValue(), thumbnailHeight.intValue(), true, x1, y1, x2, y2);
ImageUtil.processImage(this.getContext(), cropImgObj.getMendixObject(),
cropWidth, cropHeight, thumbnailWidth.intValue(), thumbnailHeight.intValue(),
true, x1, y1, x2, y2, jpegCompressionQuality.floatValue());

return true;
} else
Expand All @@ -71,7 +78,7 @@ public java.lang.Boolean executeAction() throws Exception
* Returns a string representation of this action
*/
@Override
public java.lang.String toString()
public String toString()
{
return "CropImage";
}
Expand Down
19 changes: 12 additions & 7 deletions src_module/javasource/imagecrop/actions/ScaleImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,28 @@
import com.mendix.webui.CustomJavaAction;
import imagecrop.implementation.ImageUtil;

public class ScaleImage extends CustomJavaAction<java.lang.Boolean>
/**
*
*/
public class ScaleImage extends CustomJavaAction<Boolean>
{
private IMendixObject __cropImgObj;
private imagecrop.proxies.CropImage cropImgObj;
private java.lang.Long thumbnailWidth;
private java.lang.Long thumbnailHeight;
private Long thumbnailWidth;
private Long thumbnailHeight;
private java.math.BigDecimal jpegCompressionQuality;

public ScaleImage(IContext context, IMendixObject cropImgObj, java.lang.Long thumbnailWidth, java.lang.Long thumbnailHeight)
public ScaleImage(IContext context, IMendixObject cropImgObj, Long thumbnailWidth, Long thumbnailHeight, java.math.BigDecimal jpegCompressionQuality)
{
super(context);
this.__cropImgObj = cropImgObj;
this.thumbnailWidth = thumbnailWidth;
this.thumbnailHeight = thumbnailHeight;
this.jpegCompressionQuality = jpegCompressionQuality;
}

@Override
public java.lang.Boolean executeAction() throws Exception
public Boolean executeAction() throws Exception
{
this.cropImgObj = __cropImgObj == null ? null : imagecrop.proxies.CropImage.initialize(getContext(), __cropImgObj);

Expand All @@ -45,7 +50,7 @@ public java.lang.Boolean executeAction() throws Exception

ImageUtil.processImage(this.getContext(), cropImgObj.getMendixObject(),
newWidth, newHeight, thumbnailWidth.intValue(), thumbnailHeight.intValue(),
false, 0, 0, 0, 0);
false, 0, 0, 0, 0, jpegCompressionQuality.floatValue());

return true;
} else {
Expand All @@ -58,7 +63,7 @@ public java.lang.Boolean executeAction() throws Exception
* Returns a string representation of this action
*/
@Override
public java.lang.String toString()
public String toString()
{
return "ScaleImage";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;

public class SetInitialImageProps extends CustomJavaAction<java.lang.Boolean>
/**
*
*/
public class SetInitialImageProps extends CustomJavaAction<Boolean>
{
private IMendixObject UploadedImage;

Expand All @@ -29,7 +32,7 @@ public SetInitialImageProps(IContext context, IMendixObject UploadedImage)
}

@Override
public java.lang.Boolean executeAction() throws Exception
public Boolean executeAction() throws Exception
{
// BEGIN USER CODE
try (InputStream is = Core.getImage(getContext(), this.UploadedImage, false))
Expand All @@ -56,7 +59,7 @@ public java.lang.Boolean executeAction() throws Exception
* Returns a string representation of this action
*/
@Override
public java.lang.String toString()
public String toString()
{
return "SetInitialImageProps";
}
Expand Down
43 changes: 32 additions & 11 deletions src_module/javasource/imagecrop/implementation/ImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageInputStream;

import javax.imageio.stream.MemoryCacheImageOutputStream;
import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.systemwideinterfaces.core.IMendixObject;
Expand All @@ -24,26 +26,26 @@ public ImageUtil() {
}

public static void processImageBW( IContext context, IMendixObject bwImageObj, IMendixObject colorImageObj,
int thumbnailWidth, int thumbnailHeight) throws IOException {
int thumbnailWidth, int thumbnailHeight, float jpegCompressionQuality) throws IOException {

try ( InputStream is = Core.getImage(context, colorImageObj, false) )
{
BufferedImage original = ImageIO.read(is);
BufferedImage alteredImage = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_RGB);
BufferedImage originalImage = ImageIO.read(is);
BufferedImage alteredImage = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_RGB);

ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
op.filter(original, alteredImage);
op.filter(originalImage, alteredImage);

String formatName = getFormatName(context, colorImageObj);

write(context, bwImageObj, alteredImage, formatName, thumbnailWidth, thumbnailHeight);
write(context, bwImageObj, alteredImage, formatName, thumbnailWidth, thumbnailHeight, jpegCompressionQuality);
}
}


public static void processImage(IContext context, IMendixObject imageObj,
int width, int height, int thumbnailWidth, int thumbnailHeight,
Boolean crop, int x1, int y1, int x2, int y2) {
Boolean crop, int x1, int y1, int x2, int y2, float jpegCompressionQuality) {
try ( InputStream is = Core.getImage(context, imageObj, false) )
{
BufferedImage originalImage = ImageIO.read(is);
Expand All @@ -58,7 +60,7 @@ public static void processImage(IContext context, IMendixObject imageObj,

String formatName = getFormatName(context, imageObj);

write(context, imageObj, alteredImage, formatName, thumbnailWidth, thumbnailHeight);
write(context, imageObj, alteredImage, formatName, thumbnailWidth, thumbnailHeight, jpegCompressionQuality);
} catch (IOException e) {
Core.getLogger("ImageCrop").error(e);
}
Expand Down Expand Up @@ -88,10 +90,29 @@ private static String getFormatName(IContext context, IMendixObject imageObj) th
}

private static void write( IContext context, IMendixObject imageObj, BufferedImage alteredImage, String formatName,
int thumbnailWidth, int thumbnailHeight) throws IOException
int thumbnailWidth, int thumbnailHeight, float jpegCompressionQuality) throws IOException
{
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(alteredImage, formatName, os);


if (formatName.toLowerCase().equals("jpeg") || formatName.toLowerCase().equals("jpg") ) {
float compQuality = jpegCompressionQuality;
if (compQuality < 0f) {
compQuality = 0f;
} else if (compQuality > 1f) {
compQuality = 1f;
}

ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); // Needed see javadoc
param.setCompressionQuality(compQuality); // Highest quality
writer.setOutput(new MemoryCacheImageOutputStream(os));
writer.write(null, new IIOImage(alteredImage, null, null), param);
} else {
ImageIO.write(alteredImage, formatName, os);
}

try ( InputStream stream = new ByteArrayInputStream(os.toByteArray()) )
{
Core.storeImageDocumentContent(context, imageObj, stream,
Expand Down