Sebastian Pierre
09/26/2024, 1:39 PMkirin-808
10/02/2024, 3:25 PMSebastian Pierre
10/03/2024, 8:35 AMBalázs Kerper
10/04/2024, 2:16 PM/media/mnfnj2kd/test.jpg?cc=0,0.5783864731237323,0.0006197881451430714,0&width=1920&height=1080&v=1da516670ffb050
The values you would need for cc
are what you get as a coordinates
object in the content delivery, basically the coordinates of the cropped portion of the image. What you would give as rxy
are just the focal point, which will point to the correctly selected focal point for the image but it will not know what portion is cut.
So in short, you have 3 cases:
- nothing is set (focal point or crop for the given crop alias): you can do what you have done and set the focal point to the middle
- focal points is set: use the rxy
version of the url, with height and width or any other options
- coordinates are set for the given crop: use the cc
version, with width, height or any other options
I've also ran into another issue on a personal project, that cause issues with images, described here and the linked other post: https://our.umbraco.com/forum/using-umbraco-and-getting-started/113411-query-string-image-resize-not-working-on-umbraco-12
Hope this helps.Sebastian Pierre
10/07/2024, 9:56 AMSebastian Pierre
10/08/2024, 9:48 AMfunction buildCropUrl (baseImageUrl: string, crop: Crop | undefined, imageWidth: number | null = 0) : string {
const url = new URL(baseImageUrl);
// Determine width and height values from imageWidth or crop dimensions.
const width = imageWidth && imageWidth > 0 ? imageWidth : crop?.width;
const height = crop?.height;
// Initialize an array to hold custom query parameters.
const customParams: string[] = [];
// Handle cases for cropping and focal points.
if (crop?.coordinates) {
const { x1, y1, x2, y2 } = crop.coordinates;
const cc = `${x1.toFixed(4)},${y1.toFixed(4)},${x2.toFixed(4)},${y2.toFixed(4)}`;
customParams.push(`cc=${cc}`);
}
// Add width and height after the cc.
if (width) customParams.push(`width=${width}`);
if (height) customParams.push(`height=${height}`);
// Construct the full URL with parameters in the correct order.
const queryString = customParams.join('&');
return `${url.origin}${url.pathname}?${queryString}`;
}
Balázs Kerper
10/08/2024, 12:03 PM