*.jpg files is no longer resized

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 .jpeg returns the correct url, how ca i add the shorthand?

Litium version: 7.4.2

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.

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

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

if i reupload the size gets updated

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

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).

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

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?
?

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.

1 Like

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.

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);
                    };
                }
            }
        }
    }
}

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