# Image crop issue

**URL:** https://forum.litium.com/t/image-crop-issue/1378
**Category:** Questions
**Tags:** media, litium-7
**Created:** [March 12, 2020, 9:55am UTC](https://forum.litium.com/t/image-crop-issue/1378 "2020-03-12T09:55:56Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![jonwid](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/jonwid/32/86_2.png) [@jonwid](https://forum.litium.com/u/jonwid)
#### Post date: [March 12, 2020, 9:55am UTC](https://forum.litium.com/t/image-crop-issue/1378/1 "2020-03-12T09:55:56Z")

</div>

I’m having trouble getting the image cropping to work as I expect it to. What I want is to have the image no wider than 800 and no higher than 1580. I try to do it like this.

`.GetImageUrls(_fileService, i => new ImageSize { MaxSize = new Size(800, 1580) })`

For most images this seem to work but for this one it acts strange as its not keeping the entire content. Am I doing this wrong?

Original image (6152 x 4358 px):

 ![FBLV168_orign](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/ea1109eee3d8ea135744776d34bb29fdaa9d4811.jpeg)

Cropped image (800 x 567 px):

 ![FBLV168_large_error](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/249604994a9e1f772bc71d2d9e65ddfe36c42801.jpeg)

Litium version: 7.3.2

---

<div class="post-metadata">

### Author: ![ton.nguyen](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/ton.nguyen/32/27_2.png) [@ton.nguyen](https://forum.litium.com/u/ton.nguyen)
#### Post date: [March 12, 2020, 10:42am UTC](https://forum.litium.com/t/image-crop-issue/1378/2 "2020-03-12T10:42:39Z")

</div>

What if you pass in MinSize as well so it is not Empty?

---

<div class="post-metadata">

### Author: ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)
#### Post date: [March 12, 2020, 11:19am UTC](https://forum.litium.com/t/image-crop-issue/1378/3 "2020-03-12T11:19:47Z")

</div>

How does the `GetImageUrls`-method look like?

---

<div class="post-metadata">

### Author: ![jonwid](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/jonwid/32/86_2.png) [@jonwid](https://forum.litium.com/u/jonwid)
#### Post date: [March 12, 2020, 1:51pm UTC](https://forum.litium.com/t/image-crop-issue/1378/4 "2020-03-12T13:51:58Z")

</div>

`.GetImageUrls(_fileService, i => new ImageSize { MaxSize = new Size(800, 1580), MinSize = new Size(800, 1)});` made no difference.

---

<div class="post-metadata">

### Author: ![jonwid](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/jonwid/32/86_2.png) [@jonwid](https://forum.litium.com/u/jonwid)
#### Post date: [March 12, 2020, 1:55pm UTC](https://forum.litium.com/t/image-crop-issue/1378/5 "2020-03-12T13:55:11Z")

</div>

Yeah. Sorry. It’s the default implementation in the Accelerator. `Litium.Accelerator.Extensions.FieldFrameworkExtensions`

```
public static List<string> GetImageUrls(this IFieldFramework fields, FileService fileService, Func<int, ImageSize> getImageSize = null)
{
	if (fields == null)
	{
		return null;
	}

	var imageIds = (fields[SystemFieldDefinitionConstants.Images] as IReadOnlyCollection<Guid>)?.ToArray();
	if (imageIds?.Length > 0)
	{
		var result = new List<string>();
		for (int i = 0; i < imageIds.Length; i++)
		{
			ImageSize imageSize = null;
			if (getImageSize != null)
			{
				imageSize = getImageSize(i);
			}
			var file = fileService.Get(imageIds[i]);
			var link = (imageSize != null)
				? file.GetUrlToImage(imageSize.MaxSize, imageSize.MinSize, out Size actualSize, false)
				: file.GetUrlToImage(out actualSize, false);

			result.Add(link);
		}
		return result;
	}
	else
	{
		return null;
	}
}
```

---

<div class="post-metadata">

### Author: ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)
#### Post date: [March 13, 2020, 7:22am UTC](https://forum.litium.com/t/image-crop-issue/1378/6 "2020-03-13T07:22:57Z")

</div>

Please, can you verify the original image size?

When I download that original image that you have uploaded the size says 4655x2481. What is the size Litium recognize for this image and what is the size if you upload the image again?

The `MinSize` parameter is only used when the original image size is smaller than what you want so that should not have any impact.

---

<div class="post-metadata">

### Author: ![jonwid](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/jonwid/32/86_2.png) [@jonwid](https://forum.litium.com/u/jonwid)
#### Post date: [March 13, 2020, 8:03am UTC](https://forum.litium.com/t/image-crop-issue/1378/7 "2020-03-13T08:03:31Z")

</div>

Hi. Yes, that was it. The size in Litium differed from what the actual size of the image was.  
Thanks!

---

<div class="post-metadata">

### Author: ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)
#### Post date: [March 13, 2020, 9:57am UTC](https://forum.litium.com/t/image-crop-issue/1378/8 "2020-03-13T09:57:31Z")

</div>

Is the image imported by some integration or uploaded manually? More to be able to identify what have happen to get the wrong size.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)
#### Post date: [April 10, 2020, 9:57am UTC](https://forum.litium.com/t/image-crop-issue/1378/9 "2020-04-10T09:57:37Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
