File inFile = request.getInFile();
if( null == inFile ) {
throw new Exception("Must provide a file for image conversion");
}
MultimediaConversionProgress progress = request.getProgress();
if( null == progress ) {
progress = MultimediaConversionProgressNull.getSingleton();
}
ImageMagickInfo imInfo = ImageMagick.getInfo();
// Get information about image
ImageInfo imageInfo = null;
if( imInfo.isAvailable ){
ImageMagickProcessor imageMagick = imInfo.getProcessor();
imageInfo = imageMagick.getImageInfo( inFile );
}
boolean conversionRequired = false;
boolean resizeRequired = false;
boolean reorientationRequired = false;
if( null != imageInfo ) {
request.setInHeight( imageInfo.height );
request.setInWidth( imageInfo.width );
// Check if conversion is required
conversionRequired = imageConversionThreshold.isConversionRequired(
imageInfo.format
,null
,null
,null
,new Long(imageInfo.width)
,new Long(imageInfo.height)
);
resizeRequired = imageConversionThreshold.isResizeRequired(
new Long(imageInfo.width)
,new Long(imageInfo.height)
);
if( imageInfo.orientation == ImageInfo.Orientation.REQUIRES_CONVERSION ) {
reorientationRequired = true;
}
}
if( false == conversionRequired
&& false == resizeRequired
&& false == reorientationRequired
) {
// Conversion not required, converted file is the uploaded file
// Same applies if conversion is impossible because ImageMagick
// is not present.
request.setOutFile(inFile);
progress.updateProgress(100);
} else {
File outFile = request.getOutFile();
if( null == outFile ) {
File parentDir = inFile.getParentFile();
outFile = File.createTempFile("conv", ".jpg", parentDir);