Skip to content

Commit

Permalink
enable by default
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Aug 23, 2024
1 parent 86f5b6a commit 1940ed1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<action type="update" dev="sseifert" issue="64">
Dynamic Media with OpenAPI: Do not enable support for remote assets by default. Since general availability the related configuration services not longer protected by a feature flag, so the feature has to be enabled explicitly via OSGi configuration.
</action>
<action type="update" dev="sseifert"><![CDATA[
<action type="update" dev="sseifert" issue="65"><![CDATA[
Dynamic Media: Control image quality for lossy output image for each media request by appending "qlt" URL parameter, defaulting to the default image quality configured in the media handler configuration class.<br/>
<b>Breaking change:</b> You can disable this behavior by setting "Set Image Quality" to false in the "wcm.io Media Handler Dynamic Media Support" OSGi configuration. If disabled, the default image quality setting configured in Dynamic Media is used for all images.
]]></action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class DynamicMediaSupportServiceImpl implements DynamicMediaSupportServic
@AttributeDefinition(
name = "Set Image Quality",
description = "Control image quality for lossy output formats for each media request via 'qlt' URL parameter (instead of relying on default setting within Dynamic Media).")
boolean setImageQuality() default false;
boolean setImageQuality() default true;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ void testValidSmartCroppedRenditionAndWidths() {

List<Rendition> renditions = List.copyOf(media.getRenditions());
assertEquals(2, renditions.size());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A4-3?wid=80&hei=60&fit=stretch", renditions.get(0).getUrl());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A4-3?wid=40&hei=30&fit=stretch", renditions.get(1).getUrl());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A4-3?wid=80&hei=60&fit=stretch&qlt=85", renditions.get(0).getUrl());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A4-3?wid=40&hei=30&fit=stretch&qlt=85", renditions.get(1).getUrl());
}

@Test
Expand All @@ -118,9 +118,9 @@ void testValidSmartCroppedRenditionAndWidths_DisableValidateSmartCropRenditionSi

List<Rendition> renditions = List.copyOf(media.getRenditions());
assertEquals(3, renditions.size());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A4-3?wid=100&hei=75&fit=stretch", renditions.get(0).getUrl());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A4-3?wid=80&hei=60&fit=stretch", renditions.get(1).getUrl());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A4-3?wid=40&hei=30&fit=stretch", renditions.get(2).getUrl());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A4-3?wid=100&hei=75&fit=stretch&qlt=85", renditions.get(0).getUrl());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A4-3?wid=80&hei=60&fit=stretch&qlt=85", renditions.get(1).getUrl());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A4-3?wid=40&hei=30&fit=stretch&qlt=85", renditions.get(2).getUrl());
}

@Test
Expand All @@ -144,7 +144,7 @@ void testValidSmartCroppedRendition_OnlyRatio() {

List<Rendition> renditions = List.copyOf(media.getRenditions());
assertEquals(1, renditions.size());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A4-3?wid=80&hei=60&fit=stretch", renditions.get(0).getUrl());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A4-3?wid=80&hei=60&fit=stretch&qlt=85", renditions.get(0).getUrl());
}

@Test
Expand All @@ -154,7 +154,7 @@ void testValidSmartCroppedRenditionOnlyRatio_MatchingOriginalRatio() {

List<Rendition> renditions = List.copyOf(media.getRenditions());
assertEquals(1, renditions.size());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A16-10?wid=120&hei=75&fit=stretch", renditions.get(0).getUrl());
assertEquals("https://dummy.scene7.com/is/image/DummyFolder/test%3A16-10?wid=120&hei=75&fit=stretch&qlt=85", renditions.get(0).getUrl());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ boolean isCreateAssetWithDynamicMediaMetadata() {
void testAsset_JPEG_Original() {
Asset asset = createSampleAsset("/filetype/sample.jpg", ContentType.JPEG);
buildAssertMedia(asset, 100, 50,
"https://dummy.scene7.com/is/image/DummyFolder/sample.jpg?wid=100&hei=50&fit=stretch",
"https://dummy.scene7.com/is/image/DummyFolder/sample.jpg?wid=100&hei=50&fit=stretch&qlt=85",
ContentType.JPEG);
}

Expand All @@ -74,7 +74,7 @@ void testAsset_JPEG_Original_ContentDisposition() {
void testAsset_JPEG_Rescale() {
Asset asset = createSampleAsset("/filetype/sample.jpg", ContentType.JPEG);
buildAssertMedia_Rescale(asset, 80, 40,
"https://dummy.scene7.com/is/image/DummyFolder/sample.jpg?wid=80&hei=40&fit=stretch",
"https://dummy.scene7.com/is/image/DummyFolder/sample.jpg?wid=80&hei=40&fit=stretch&qlt=85",
ContentType.JPEG);
}

Expand All @@ -83,7 +83,7 @@ void testAsset_JPEG_Rescale() {
void testAsset_JPEG_AutoCrop() {
Asset asset = createSampleAsset("/filetype/sample.jpg", ContentType.JPEG);
buildAssertMedia_AutoCrop(asset, 50, 50,
"https://dummy.scene7.com/is/image/DummyFolder/sample.jpg?crop=25,0,50,50&wid=50&hei=50&fit=stretch",
"https://dummy.scene7.com/is/image/DummyFolder/sample.jpg?crop=25,0,50,50&wid=50&hei=50&fit=stretch&qlt=85",
ContentType.JPEG);
}

Expand All @@ -92,7 +92,7 @@ void testAsset_JPEG_AutoCrop() {
void testAsset_JPEG_AutoCrop_ImageQuality() {
Asset asset = createSampleAsset("/filetype/sample.jpg", ContentType.JPEG);
buildAssertMedia_AutoCrop(asset, 50, 50,
"https://dummy.scene7.com/is/image/DummyFolder/sample.jpg?crop=25,0,50,50&wid=50&hei=50&fit=stretch",
"https://dummy.scene7.com/is/image/DummyFolder/sample.jpg?crop=25,0,50,50&wid=50&hei=50&fit=stretch&qlt=60",
ContentType.JPEG, 0.6d);
}

Expand All @@ -102,7 +102,7 @@ void testAsset_JPEG_CropWithExplicitRendition() {
Asset asset = createSampleAsset("/filetype/sample.jpg", ContentType.JPEG);
context.create().assetRendition(asset, "square.jpg", 50, 50, ContentType.JPEG);
buildAssertMedia_AutoCrop(asset, 50, 50,
"https://dummy.scene7.com/is/image/DummyFolder/sample.jpg?crop=25,0,50,50&wid=50&hei=50&fit=stretch",
"https://dummy.scene7.com/is/image/DummyFolder/sample.jpg?crop=25,0,50,50&wid=50&hei=50&fit=stretch&qlt=85",
ContentType.JPEG);
}

Expand Down Expand Up @@ -148,7 +148,7 @@ void testAsset_GIF_Original() {
void testAsset_GIF_Rescale() {
Asset asset = createSampleAsset("/filetype/sample.gif", ContentType.GIF);
buildAssertMedia_Rescale(asset, 80, 40,
"https://dummy.scene7.com/is/image/DummyFolder/sample.gif?wid=80&hei=40&fit=stretch",
"https://dummy.scene7.com/is/image/DummyFolder/sample.gif?wid=80&hei=40&fit=stretch&qlt=85",
ContentType.JPEG);
}

Expand All @@ -157,7 +157,7 @@ void testAsset_GIF_Rescale() {
void testAsset_GIF_AutoCrop() {
Asset asset = createSampleAsset("/filetype/sample.gif", ContentType.GIF);
buildAssertMedia_AutoCrop(asset, 50, 50,
"https://dummy.scene7.com/is/image/DummyFolder/sample.gif?crop=25,0,50,50&wid=50&hei=50&fit=stretch",
"https://dummy.scene7.com/is/image/DummyFolder/sample.gif?crop=25,0,50,50&wid=50&hei=50&fit=stretch&qlt=85",
ContentType.JPEG);
}

Expand Down Expand Up @@ -235,7 +235,7 @@ void testFileUpload_PNG_AutoCrop() {
void testAsset_TIFF_Original() {
Asset asset = createSampleAsset("/filetype/sample.tif", ContentType.TIFF);
buildAssertMedia(asset, 100, 50,
"https://dummy.scene7.com/is/image/DummyFolder/sample.tif?wid=100&hei=50&fit=stretch",
"https://dummy.scene7.com/is/image/DummyFolder/sample.tif?wid=100&hei=50&fit=stretch&qlt=85",
ContentType.JPEG);
}

Expand All @@ -253,7 +253,7 @@ void testAsset_TIFF_Original_ContentDisposition() {
void testAsset_TIFF_Rescale() {
Asset asset = createSampleAsset("/filetype/sample.tif", ContentType.TIFF);
buildAssertMedia_Rescale(asset, 80, 40,
"https://dummy.scene7.com/is/image/DummyFolder/sample.tif?wid=80&hei=40&fit=stretch",
"https://dummy.scene7.com/is/image/DummyFolder/sample.tif?wid=80&hei=40&fit=stretch&qlt=85",
ContentType.JPEG);
}

Expand All @@ -262,7 +262,7 @@ void testAsset_TIFF_Rescale() {
void testAsset_TIFF_AutoCrop() {
Asset asset = createSampleAsset("/filetype/sample.tif", ContentType.TIFF);
buildAssertMedia_AutoCrop(asset, 50, 50,
"https://dummy.scene7.com/is/image/DummyFolder/sample.tif?crop=25,0,50,50&wid=50&hei=50&fit=stretch",
"https://dummy.scene7.com/is/image/DummyFolder/sample.tif?crop=25,0,50,50&wid=50&hei=50&fit=stretch&qlt=85",
ContentType.JPEG);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.osgi.framework.Constants;

import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.DamConstants;
Expand Down Expand Up @@ -82,14 +83,27 @@ void setUp() {

@Test
void testWidthHeight() {
String result = DynamicMediaPath.buildImage(damContext, 30, 25);
assertEquals("/is/image/DummyFolder/test?wid=30&hei=25&fit=stretch&qlt=85", result);
}

@Test
void testWidthHeight_DisableSetImageQuality() {
// disable setImageQuality option
dynamicMediaSupportService = context.registerInjectActivateService(DynamicMediaSupportServiceImpl.class,
"setImageQuality", false,
Constants.SERVICE_RANKING, 1000);
damContext = new DamContext(asset, new MediaArgs(), mediaHandlerConfig,
dynamicMediaSupportService, webOptimizedImageDeliveryService, context.request());

String result = DynamicMediaPath.buildImage(damContext, 30, 25);
assertEquals("/is/image/DummyFolder/test?wid=30&hei=25&fit=stretch", result);
}

@Test
void testWidthHeight_ImplicitSmartCrop() {
String result = DynamicMediaPath.buildImage(damContext, 30, 20);
assertEquals("/is/image/DummyFolder/test%3ACrop-1?wid=30&hei=20&fit=stretch", result);
assertEquals("/is/image/DummyFolder/test%3ACrop-1?wid=30&hei=20&fit=stretch&qlt=85", result);
}

@Test
Expand All @@ -106,49 +120,49 @@ void testWidthHeight_ImplicitSmartCrop_CroppingAreaTooSmall() {
@Test
void testCrop() {
String result = DynamicMediaPath.buildImage(damContext, 30, 20, new CropDimension(5, 2, 10, 8), null);
assertEquals("/is/image/DummyFolder/test?crop=5,2,10,8&wid=30&hei=20&fit=stretch", result);
assertEquals("/is/image/DummyFolder/test?crop=5,2,10,8&wid=30&hei=20&fit=stretch&qlt=85", result);
}

@Test
void testAutoCrop_SmartCrop() {
String result = DynamicMediaPath.buildImage(damContext, 30, 20, new CropDimension(5, 2, 10, 8, true), null);
assertEquals("/is/image/DummyFolder/test%3ACrop-1?wid=30&hei=20&fit=stretch", result);
assertEquals("/is/image/DummyFolder/test%3ACrop-1?wid=30&hei=20&fit=stretch&qlt=85", result);
}

@Test
void testWidthHeight_MaxWidth() {
String result = DynamicMediaPath.buildImage(damContext, 3000, 1500);
assertEquals("/is/image/DummyFolder/test?wid=2000&hei=1000&fit=stretch", result);
assertEquals("/is/image/DummyFolder/test?wid=2000&hei=1000&fit=stretch&qlt=85", result);
}

@Test
void testWidthHeight_MaxHeight() {
String result = DynamicMediaPath.buildImage(damContext, 2500, 5000);
assertEquals("/is/image/DummyFolder/test?wid=1000&hei=2000&fit=stretch", result);
assertEquals("/is/image/DummyFolder/test?wid=1000&hei=2000&fit=stretch&qlt=85", result);
}

@Test
void testWidthHeight_MaxWidthHeight() {
String result = DynamicMediaPath.buildImage(damContext, 6000, 8000);
assertEquals("/is/image/DummyFolder/test?wid=1500&hei=2000&fit=stretch", result);
assertEquals("/is/image/DummyFolder/test?wid=1500&hei=2000&fit=stretch&qlt=85", result);
}

@Test
void testRotate() {
String result = DynamicMediaPath.buildImage(damContext, 30, 20, null, 180);
assertEquals("/is/image/DummyFolder/test?rotate=180&wid=30&hei=20&fit=stretch", result);
assertEquals("/is/image/DummyFolder/test?rotate=180&wid=30&hei=20&fit=stretch&qlt=85", result);
}

@Test
void testCropRotate() {
String result = DynamicMediaPath.buildImage(damContext, 30, 20, new CropDimension(5, 2, 10, 8), 90);
assertEquals("/is/image/DummyFolder/test?crop=5,2,10,8&rotate=90&wid=30&hei=20&fit=stretch", result);
assertEquals("/is/image/DummyFolder/test?crop=5,2,10,8&rotate=90&wid=30&hei=20&fit=stretch&qlt=85", result);
}

@Test
void testAutoCropRotate_NoSmartCrop() {
String result = DynamicMediaPath.buildImage(damContext, 30, 20, new CropDimension(5, 2, 10, 8, true), 90);
assertEquals("/is/image/DummyFolder/test?crop=5,2,10,8&rotate=90&wid=30&hei=20&fit=stretch", result);
assertEquals("/is/image/DummyFolder/test?crop=5,2,10,8&rotate=90&wid=30&hei=20&fit=stretch&qlt=85", result);
}

@Test
Expand Down

0 comments on commit 1940ed1

Please sign in to comment.