private static List<EffectData> generateVideoEffects(Context context, Resource resource) { List<EffectData> effects = new ArrayList<>(); Transformation transformation; transformation = new Transformation().angle(20); effects.add(new EffectData(resource.getCloudinaryPublicId(), transformation, context.getString(R.string.effect_video_name_rotation), context.getString(R.string.effect_video_rotate))); transformation = new Transformation().effect("fade", 1000); effects.add(new EffectData(resource.getCloudinaryPublicId(), transformation, context.getString(R.string.effect_video_name_fade_in), context.getString(R.string.effect_video_fade_in))); transformation = new Transformation().chain().overlay("video:" + resource.getCloudinaryPublicId()).width(0.5).flags("relative").gravity("north_east"); effects.add(new EffectData(resource.getCloudinaryPublicId(), transformation, context.getString(R.string.effect_video_name_overlay), context.getString(R.string.effect_desc_video_overlay))); transformation = new Transformation().effect("noise", 50); effects.add(new EffectData(resource.getCloudinaryPublicId(), transformation, context.getString(R.string.effect_video_name_noise), context.getString(R.string.effect_desc_video_noise))); transformation = new Transformation().effect("blur", 200); effects.add(new EffectData(resource.getCloudinaryPublicId(), transformation, context.getString(R.string.effect_video_name_blur), context.getString(R.string.effect_desc_video_blur))); transformation = new Transformation().effect("reverse"); effects.add(new EffectData(resource.getCloudinaryPublicId(), transformation, context.getString(R.string.effect_video_name_reverse), context.getString(R.string.effect_desc_video_reverse))); return effects; }
/** * Construct the final url with the dimensions included as the last transformation in the url. * @param view The view to adapt the image size to. * @param baseUrl The base cloudinary Url to chain the transformation to. * @return The url with the responsive transformation. */ private Url buildUrl(View view, Url baseUrl) { // add a new transformation on top of anything already there: Url url = baseUrl.clone(); url.transformation().chain(); if (autoHeight) { int contentHeight = view.getHeight() - view.getPaddingTop() - view.getPaddingBottom(); url.transformation().height(trimAndRoundUp(contentHeight)); } if (autoWidth) { int contentWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight(); url.transformation().width(trimAndRoundUp(contentWidth)); } url.transformation().crop(cropMode).gravity(gravity); return url; }
public static String getCroppedThumbnailUrl(int size, Resource resource) { return MediaManager.get().getCloudinary().url() .resourceType(resource.getResourceType()) .transformation(new Transformation().gravity("auto").width(size).height(size)) .format("webp") .generate(resource.getCloudinaryPublicId()); }
@Test @TestCaseName("{method}: {0}") @Parameters public void testAutoGravity(String value, String serialized) { Transformation transformation = new Transformation().crop("crop").gravity(value).width(0.5f); String result = cloudinary.url().transformation(transformation).generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "c_crop," + serialized + ",w_0.5/test", result); }
@Test public void testVariousOptions() { // should use x, y, radius, prefix, gravity and quality from options Transformation transformation = new Transformation().x(1).y(2).radius(3).gravity("center").quality(0.4).prefix("a"); String result = cloudinary.url().transformation(transformation).generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "g_center,p_a,q_0.4,r_3,x_1,y_2/test", result); }
expectedTag = String.format(expectedTag, posterUrl, expectedUrl); actualTag = cloudinary.url().sourceTypes(new String[]{"mp4"}) .poster(new Transformation().gravity("north")) .videoTag("movie", emptyMap()); assertEquals(expectedTag, actualTag); .publicId("my_poster") .format("jpg") .transformation(new Transformation().gravity("north"))) .videoTag("movie", emptyMap()); assertEquals(expectedTag, actualTag);