REPO-3720 MNT-19825 ImageMagick docker transformer does not take arbitrary command line options.

Cherry picked 4772e0493e from master (ACS 6.1.0) to 6.56.N (ACS 6.0.0)
This commit is contained in:
Alan Davis
2018-07-24 11:31:41 +01:00
parent 4135dc550c
commit 4e95e33d37
3 changed files with 60 additions and 32 deletions

View File

@@ -260,12 +260,16 @@ public class ImageMagickContentTransformerWorker extends AbstractImageMagickCont
String allowEnlargement = null;
String maintainAspectRatio = null;
String commandOptions = null;
if (options instanceof ImageTransformationOptions)
{
ImageTransformationOptions imageOptions = (ImageTransformationOptions)options;
CropSourceOptions cropOptions = imageOptions.getSourceOptions(CropSourceOptions.class);
ImageResizeOptions resizeOptions = imageOptions.getResizeOptions();
commandOptions = imageOptions.getCommandOptions();
commandOptions = commandOptions == null || "".equals(commandOptions.trim()) ? null : commandOptions.trim();
// MNT-10882 : JPEG File Format, does not save the alpha (transparency) channel.
if (MimetypeMap.MIMETYPE_IMAGE_JPEG.equalsIgnoreCase(targetMimetype) && isAlphaOptionSupported())
@@ -374,7 +378,10 @@ public class ImageMagickContentTransformerWorker extends AbstractImageMagickCont
"resizeHeight", resizeHeight,
"resizePercentage", resizePercentage,
"allowEnlargement", allowEnlargement,
"maintainAspectRatio", maintainAspectRatio);
"maintainAspectRatio", maintainAspectRatio,
// Parameter not to be taken forward into the Transform Service version
"commandOptions", commandOptions);
}
protected String getImageMagickVersionNumber()

View File

@@ -53,9 +53,11 @@ public class ImageTransformationOptions extends TransformationOptions
private boolean autoOrient = true;
/**
* Set the command string options
* @deprecated will be removed in a future release and be replaced by individual options that can be checked.
*
* @param commandOptions the command string options
*/
@Deprecated
public void setCommandOptions(String commandOptions)
{
this.commandOptions = commandOptions;
@@ -63,9 +65,11 @@ public class ImageTransformationOptions extends TransformationOptions
/**
* Get the command string options
* @deprecated will be removed in a future release and be replaced by individual options that can be checked.
*
* @return String the command string options
*/
@Deprecated
public String getCommandOptions()
{
return commandOptions;

View File

@@ -44,7 +44,7 @@ import org.alfresco.service.cmr.repository.TransformationSourceOptions;
import org.alfresco.util.TempFileProvider;
/**
* @see org.alfresco.repo.content.transform.magick.JMagickContentTransformer
* @see org.alfresco.repo.content.transform.magick.ImageMagickContentTransformerWorker
*
* @author Derek Hulley
*/
@@ -89,8 +89,9 @@ public class ImageMagickContentTransformerTest extends AbstractContentTransforme
assertEquals("Mimetype should be supported", true, reliability);
}
protected void transform(String sourceMimetype, String targetMimetype, TransformationOptions options) throws IOException
protected long transform(String sourceMimetype, String targetMimetype, TransformationOptions options) throws IOException
{
long size = -1;
String[] quickFiles = getQuickFilenames(sourceMimetype);
for (String quickFile : quickFiles)
{
@@ -116,8 +117,10 @@ public class ImageMagickContentTransformerTest extends AbstractContentTransforme
targetWriter.setMimetype(targetMimetype);
transformer.transform(sourceReader.getReader(), targetWriter, options);
ContentReader targetReader = targetWriter.getReader();
assertTrue(targetReader.getSize() > 0);
size = targetReader.getSize();
assertTrue(size > 0);
}
return size;
}
public void testGifToPng() throws Exception
@@ -132,6 +135,20 @@ public class ImageMagickContentTransformerTest extends AbstractContentTransforme
transform(MimetypeMap.MIMETYPE_IMAGE_JPEG, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
}
public void testDeprecatedCommandOptions() throws Exception
{
// The commandOption should be removed, but is currently needed for custom renditions.
// This test uses it to resize the file. This happens to be one of the standard options.
ImageTransformationOptions options = new ImageTransformationOptions();
long defaultSize = transform(MimetypeMap.MIMETYPE_IMAGE_JPEG, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
options.setCommandOptions("-resize 200%");
long biggerSize = transform(MimetypeMap.MIMETYPE_IMAGE_JPEG, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
assertTrue("The commandOption appears not to have been used as the file size " + biggerSize +
" is not larger than the default size " + defaultSize, biggerSize > defaultSize);
}
public void testPageSourceOptions() throws Exception
{
// Test empty source options