# \*.jpg files is no longer resized

**URL:** https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463
**Category:** Questions
**Created:** [May 4, 2020, 12:05pm UTC](https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463 "2020-05-04T12:05:19Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Robin.w](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/robin.w/32/75_2.png) [@Robin.w](https://forum.litium.com/u/Robin.w)
#### Post date: [May 4, 2020, 12:05pm UTC](https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463/1 "2020-05-04T12:05:20Z")

</div>

Hi, when generating resized image url’s eg: .GetUrlToImage(new Size(0, 0), new Size(400, 400)).Url  
.jpg images returns the full image, only .jp **e** g returns the correct url, how ca i add the shorthand?

Litium version: 7.4.2

---

<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: [May 4, 2020, 2:26pm UTC](https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463/2 "2020-05-04T14:26:57Z")

</div>

Sounds strange, ensure that you have the width/height on the image when you view that in back office. If you still have the problem even when the dimension parameter exists, please report a bug.

---

<div class="post-metadata">

### Author: ![Robin.w](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/robin.w/32/75_2.png) [@Robin.w](https://forum.litium.com/u/Robin.w)
#### Post date: [May 5, 2020, 5:43am UTC](https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463/3 "2020-05-05T05:43:30Z")

</div>

oki, so all our .jpg images (thousands) on the site now have 0x0 in the backoffice, What to do? 😃

---

<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: [May 5, 2020, 6:09am UTC](https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463/4 "2020-05-05T06:09:28Z")

</div>

If you upload one of the images again; that have size 0x0, will that image get correct size?

---

<div class="post-metadata">

### Author: ![Robin.w](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/robin.w/32/75_2.png) [@Robin.w](https://forum.litium.com/u/Robin.w)
#### Post date: [May 5, 2020, 6:32am UTC](https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463/5 "2020-05-05T06:32:42Z")

</div>

if i reupload the size gets updated

---

<div class="post-metadata">

### Author: ![Robin.w](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/robin.w/32/75_2.png) [@Robin.w](https://forum.litium.com/u/Robin.w)
#### Post date: [May 5, 2020, 7:40am UTC](https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463/6 "2020-05-05T07:40:48Z")

</div>

Can I somehow add a hook/decorator when the resize code is called to reclculate the size meta If the size is 0?

---

<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: [May 5, 2020, 7:49am UTC](https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463/7 "2020-05-05T07:49:19Z")

</div>

I have seen this problem with empty size in integrations where the integration not calling the `MetadataExtractor.UpdateMetadata` on the created file or using the `FileService.Create`-extension method that will use the file stream.

You can try with the following SQL script and then restart the system (one server in multiserver environment and distributed cache turned off, remember to remove all media files entities from distributed cache after this execution).

```sql
INSERT INTO Media.FileFieldData (OwnerSystemId, FieldDefinitionId, ChildIndex, ChildOwnerId, Culture, BooleanValue)
SELECT F.SystemId, '_needMetadataExtraction', 0, '', '*', 1 FROM Media.[File] F
	LEFT JOIN Media.FileFieldData W ON F.SystemId = W.OwnerSystemId AND W.FieldDefinitionId = '_width'
	LEFT JOIN Media.FileFieldData H ON F.SystemId = H.OwnerSystemId AND H.FieldDefinitionId = '_height' 
	LEFT JOIN Media.FileFieldData M ON F.SystemId = M.OwnerSystemId AND H.FieldDefinitionId = '_needMetadataExtraction' 
WHERE 1 = 1
	AND (W.IntValue IS NULL OR W.IntValue IN (-1, 0))
	AND (H.IntValue IS NULL OR H.IntValue IN (-1, 0)) 
	AND M.BooleanValue IS NULL

```

---

<div class="post-metadata">

### Author: ![Robin.w](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/robin.w/32/75_2.png) [@Robin.w](https://forum.litium.com/u/Robin.w)
#### Post date: [May 5, 2020, 10:11am UTC](https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463/8 "2020-05-05T10:11:53Z")

</div>

This affects 35000 rows, safe to run in production or will the site be down for a long while on restart? or is it only when the images are hit that they regenerate?  
?

---

<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: [May 5, 2020, 11:12am UTC](https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463/9 "2020-05-05T11:12:02Z")

</div>

I was taking a deeper look at the script and I can now see that the script is not setting the size property. When the size not are set the system is not generating a new image with the new size and always deliver the original image. When the size are set the resizer will create new sized version when requested.

I will provide with a new script/program that can be executed to correct this. During the time, please check that your import script (if the image come from the integration) are setting the size properties.

---

<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: [May 6, 2020, 2:43pm UTC](https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463/10 "2020-05-06T14:43:22Z")

</div>

Apply below code into the solution and deploy to one web/app server and the images should be updated with correct dimension during next startup. After the process have completed it will not be executed again.

```cs
using System;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using Litium.Blobs;
using Litium.Common;
using Litium.FieldFramework;
using Litium.Foundation;
using Litium.Foundation.Data.MSSQL.Utilities;
using Litium.Media;
using Litium.Owin.Lifecycle;

namespace Litium.Accelerator.Tasks
{
    public class ImageSizeCorrection : IStartupTaskAsync
    {
        private readonly BlobService _blobService;
        private readonly FileService _fileService;
        private readonly FileMetadataExtractorService _fileMetadataExtractorService;
        private readonly FieldTemplateService _fieldTemplateService;
        private readonly SettingService _settingService;

        public ImageSizeCorrection(
            BlobService blobService,
            FileService fileService,
            FileMetadataExtractorService fileMetadataExtractorService,
            FieldTemplateService fieldTemplateService,
            SettingService settingService)
        {
            _blobService = blobService;
            _fileService = fileService;
            _fileMetadataExtractorService = fileMetadataExtractorService;
            _fieldTemplateService = fieldTemplateService;
            _settingService = settingService;
        }

        public async Task Start()
        {
            if (!_settingService.Get<bool>("MediaMigration-CorrectFileDimensions"))
            {
                using (Solution.Instance.SystemToken.Use("MediaMigration"))
                {
                    using var db = MSSQLUtilities.OpenConnection(null);
                    var result = (await db.QueryAsync<Guid>(@"SELECT F.SystemId
FROM Media.[File] F
	LEFT JOIN Media.FileFieldData W ON F.SystemId = W.OwnerSystemId AND W.FieldDefinitionId = '_width'
	LEFT JOIN Media.FileFieldData H ON F.SystemId = H.OwnerSystemId AND H.FieldDefinitionId = '_height' 
WHERE 1 = 1
	AND (W.IntValue IS NULL OR W.IntValue IN (-1, 0))
	AND (H.IntValue IS NULL OR H.IntValue IN (-1, 0))")).ToList();
                    if (Parallel.ForEach(result, new ParallelOptions { MaxDegreeOfParallelism = 8 }, fileId =>
                    {
                        using (new Owin.Logging.CorrelationScope())
                        {
                            var file = _fileService.Get(fileId)?.MakeWritableClone();
                            if (file is null)
                            {
                                return;
                            }

                            var blobContainer = _blobService.Get(file.BlobUri);
                            using (var stream = blobContainer?.GetDefault()?.OpenRead())
                            {
                                if (stream == null)
                                {
                                    this.Log().Error($"Unable to process file {file.SystemId}. File stream not found");
                                    return;
                                }

                                _fileMetadataExtractorService.UpdateMetadata(_fieldTemplateService.Get<FileFieldTemplate>(file.FieldTemplateSystemId), file, stream, file.BlobUri);
                            }

                            _fileService.Update(file);
                            this.Log().Trace($"The File {file.Name} has been processed successfully.");
                        }
                    }).IsCompleted)
                    {
                        _settingService.Set("MediaMigration-CorrectFileDimensions", true);
                    };
                }
            }
        }
    }
}

```

---

<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: [June 3, 2020, 2:43pm UTC](https://forum.litium.com/t/jpg-files-is-no-longer-resized/1463/11 "2020-06-03T14:43:28Z")

</div>

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