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

View File

@@ -1,28 +1,28 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.repo.content.transform.magick; package org.alfresco.repo.content.transform.magick;
import java.util.HashMap; import java.util.HashMap;
@@ -53,9 +53,11 @@ public class ImageTransformationOptions extends TransformationOptions
private boolean autoOrient = true; private boolean autoOrient = true;
/** /**
* Set the command string options * 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 * @param commandOptions the command string options
*/ */
@Deprecated
public void setCommandOptions(String commandOptions) public void setCommandOptions(String commandOptions)
{ {
this.commandOptions = commandOptions; this.commandOptions = commandOptions;
@@ -63,9 +65,11 @@ public class ImageTransformationOptions extends TransformationOptions
/** /**
* Get the command string options * 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 * @return String the command string options
*/ */
@Deprecated
public String getCommandOptions() public String getCommandOptions()
{ {
return commandOptions; return commandOptions;

View File

@@ -44,7 +44,7 @@ import org.alfresco.service.cmr.repository.TransformationSourceOptions;
import org.alfresco.util.TempFileProvider; import org.alfresco.util.TempFileProvider;
/** /**
* @see org.alfresco.repo.content.transform.magick.JMagickContentTransformer * @see org.alfresco.repo.content.transform.magick.ImageMagickContentTransformerWorker
* *
* @author Derek Hulley * @author Derek Hulley
*/ */
@@ -89,8 +89,9 @@ public class ImageMagickContentTransformerTest extends AbstractContentTransforme
assertEquals("Mimetype should be supported", true, reliability); 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); String[] quickFiles = getQuickFilenames(sourceMimetype);
for (String quickFile : quickFiles) for (String quickFile : quickFiles)
{ {
@@ -116,8 +117,10 @@ public class ImageMagickContentTransformerTest extends AbstractContentTransforme
targetWriter.setMimetype(targetMimetype); targetWriter.setMimetype(targetMimetype);
transformer.transform(sourceReader.getReader(), targetWriter, options); transformer.transform(sourceReader.getReader(), targetWriter, options);
ContentReader targetReader = targetWriter.getReader(); ContentReader targetReader = targetWriter.getReader();
assertTrue(targetReader.getSize() > 0); size = targetReader.getSize();
assertTrue(size > 0);
} }
return size;
} }
public void testGifToPng() throws Exception public void testGifToPng() throws Exception
@@ -125,13 +128,27 @@ public class ImageMagickContentTransformerTest extends AbstractContentTransforme
ImageTransformationOptions options = new ImageTransformationOptions(); ImageTransformationOptions options = new ImageTransformationOptions();
transform(MimetypeMap.MIMETYPE_IMAGE_GIF, MimetypeMap.MIMETYPE_IMAGE_PNG, options); transform(MimetypeMap.MIMETYPE_IMAGE_GIF, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
} }
public void testJpegToPng() throws Exception public void testJpegToPng() throws Exception
{ {
ImageTransformationOptions options = new ImageTransformationOptions(); ImageTransformationOptions options = new ImageTransformationOptions();
transform(MimetypeMap.MIMETYPE_IMAGE_JPEG, MimetypeMap.MIMETYPE_IMAGE_PNG, options); 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 public void testPageSourceOptions() throws Exception
{ {
// Test empty source options // Test empty source options