spatie / laravel-medialibrary

Associate files with Eloquent models
https://spatie.be/docs/laravel-medialibrary
MIT License
5.77k stars 1.07k forks source link

Some conversions are not generated #3309

Closed chimit closed 10 months ago

chimit commented 1 year ago

I use Redis queues (via Horizon) to generate conversions (small, medium, and large). Images are stored in S3 (DigitalOcean Spaces). Everything works fine but sometimes conversions are not generated. And there are no clues because in Horizon such jobs look successful:

image

One of the skipped examples:

image
{
    "conversions": {
        "items": [
            {
                "fileNamer": {},
                "extractVideoFrameAtSecond": 0,
                "manipulations": {
                    "manipulationSequence": {
                        "groups": [
                            {
                                "optimize": "{"Spatie\\ImageOptimizer\\Optimizers\\Jpegoptim":["-m85","--force","--strip-all","--all-progressive"],"Spatie\\ImageOptimizer\\Optimizers\\Pngquant":["--force"],"Spatie\\ImageOptimizer\\Optimizers\\Optipng":["-i0","-o2","-quiet"],"Spatie\\ImageOptimizer\\Optimizers\\Svgo":["--disable=cleanupIDs"],"Spatie\\ImageOptimizer\\Optimizers\\Gifsicle":["-b","-O3"],"Spatie\\ImageOptimizer\\Optimizers\\Cwebp":["-m 6","-pass 10","-mt","-q 90"]}",
                                "format": "jpg",
                                "width": "600",
                                "height": "600",
                                "fit": "max"
                            }
                        ]
                    }
                },
                "performOnCollections": [],
                "performOnQueue": true,
                "keepOriginalImageFormat": true,
                "generateResponsiveImages": false,
                "loadingAttributeValue": null,
                "pdfPageNumber": 1,
                "name": "small"
            },
            {
                "fileNamer": {},
                "extractVideoFrameAtSecond": 0,
                "manipulations": {
                    "manipulationSequence": {
                        "groups": [
                            {
                                "optimize": "{"Spatie\\ImageOptimizer\\Optimizers\\Jpegoptim":["-m85","--force","--strip-all","--all-progressive"],"Spatie\\ImageOptimizer\\Optimizers\\Pngquant":["--force"],"Spatie\\ImageOptimizer\\Optimizers\\Optipng":["-i0","-o2","-quiet"],"Spatie\\ImageOptimizer\\Optimizers\\Svgo":["--disable=cleanupIDs"],"Spatie\\ImageOptimizer\\Optimizers\\Gifsicle":["-b","-O3"],"Spatie\\ImageOptimizer\\Optimizers\\Cwebp":["-m 6","-pass 10","-mt","-q 90"]}",
                                "format": "jpg",
                                "width": "960",
                                "height": "960",
                                "fit": "max",
                                "watermark": "/home/example/example.com/public/images/watermark.png",
                                "watermarkOpacity": "50",
                                "watermarkWidth": "10w",
                                "watermarkPaddingX": "18",
                                "watermarkPaddingY": "18"
                            }
                        ]
                    }
                },
                "performOnCollections": [],
                "performOnQueue": true,
                "keepOriginalImageFormat": true,
                "generateResponsiveImages": false,
                "loadingAttributeValue": null,
                "pdfPageNumber": 1,
                "name": "medium"
            },
            {
                "fileNamer": {},
                "extractVideoFrameAtSecond": 0,
                "manipulations": {
                    "manipulationSequence": {
                        "groups": [
                            {
                                "optimize": "{"Spatie\\ImageOptimizer\\Optimizers\\Jpegoptim":["-m85","--force","--strip-all","--all-progressive"],"Spatie\\ImageOptimizer\\Optimizers\\Pngquant":["--force"],"Spatie\\ImageOptimizer\\Optimizers\\Optipng":["-i0","-o2","-quiet"],"Spatie\\ImageOptimizer\\Optimizers\\Svgo":["--disable=cleanupIDs"],"Spatie\\ImageOptimizer\\Optimizers\\Gifsicle":["-b","-O3"],"Spatie\\ImageOptimizer\\Optimizers\\Cwebp":["-m 6","-pass 10","-mt","-q 90"]}",
                                "format": "jpg",
                                "width": "1280",
                                "height": "1280",
                                "fit": "max",
                                "watermark": "/home/example/example.com/public/images/watermark.png",
                                "watermarkOpacity": "50",
                                "watermarkWidth": "10w",
                                "watermarkPaddingX": "24",
                                "watermarkPaddingY": "24"
                            }
                        ]
                    }
                },
                "performOnCollections": [],
                "performOnQueue": true,
                "keepOriginalImageFormat": true,
                "generateResponsiveImages": false,
                "loadingAttributeValue": null,
                "pdfPageNumber": 1,
                "name": "large"
            }
        ],
        "escapeWhenCastingToString": false
    },
    "media": {
        "class": "Spatie\MediaLibrary\MediaCollections\Models\Media",
        "id": 21992,
        "relations": [],
        "connection": "mysql",
        "collectionClass": null
    },
    "onlyMissing": false,
    "connection": "redis",
    "queue": ""
}

In DO Spaces there is one original file without conversions.

The only suspicious thing here is the duration of the job - it's too short comparing other successful conversions. So I can only guess something wrong happens during the conversion and medialibrary is unaware of these failures, marking such jobs as done. Or medialibrary for some reason mistakenly thinks there is nothing to convert for some images and skips the job.

Running php artisan media-library:regenerate --only-missing successfully regenerates such missing conversions.

FlashWS commented 1 year ago

Absolutely similar situation PHP 8.2.7 spatie/laravel-medialibrary 10.10.1

Cigoler commented 1 year ago

Have you installed the file convertors on your server?

sudo apt install jpegoptim optipng pngquant gifsicle
npm install -g svgo
chimit commented 1 year ago

@Cigoler yes, I have them.

chimit commented 1 year ago

The generated_conversions field is empty for such images if it helps in investigation.

INSERT INTO `media` (`id`, `model_type`, `model_id`, `uuid`, `collection_name`, `name`, `file_name`, `mime_type`, `disk`, `conversions_disk`, `size`, `manipulations`, `custom_properties`, `generated_conversions`, `responsive_images`, `order_column`, `created_at`, `updated_at`)
VALUES
    (26243, 'App\\Models\\Listing', 443, '2c41472b-fd00-4e76-ba9d-d9b035492339', 'shared', 'photo', 'photo.jpeg', 'image/jpeg', 'media', 'media', 12818732, '[]', '[]', '[]', '[]', 1, '2023-08-21 05:16:31', '2023-08-21 05:16:52');
abdelwahidJobs commented 11 months ago

Same here using php 7.4 and ^8.7 not all but some photos are not generated Can anyone help ? WhatsApp Image 2023-11-27 at 11 50 34 AM (2)

freekmurze commented 10 months ago

Since there aren't too many complaining about this, I'm assuming it's caused by something at your end. Moving this to a discussion.