• Resolved enkirch

    (@enkirch)


    Hi,
    Users can upload images to our site. A function then creates several image formats from the image.

    The question I have is, at that moment I know the image path with all the images.

    Could I somehow then say, with an API call or similar, please optimise these images into folders?

    That way I could avoid scanning and being “overwhelmed”.

    By overwhelmed I mean I have, for example, a year/month folder, let’s call it “2023/03”. There are 3000 folders in there. Each folder can contain up to 50 images.

    If I now run the mass optimiser only on the March folder, it returns about 200 images as a result. After I have finished optimising, I scan again and it gives me 300 pictures again.

    Instead of giving me all the images that have not yet been optimised.

    At the beginning, when I started with the March folder, it still found 20000 images as a result. These small batches of images only seem to appear towards the end.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author nosilver4u

    (@nosilver4u)

    Certainly, you could run the core ewww_image_optimizer() function once you have the path and are done with any modifications:

    if ( function_exists( 'ewww_image_optimizer' ) ) {
        ewww_image_optimizer( $path );
    }
    Thread Starter enkirch

    (@enkirch)

    That sounds good.

    Is the following also guaranteed with the call

    • Check if the images have already been compressed to prevent double compression
    • At the moment when I create several small image formats from the original images, it can also happen that I do this for several customers. If I now process 2 customers, I would also have to call the function twice with different paths. is this a problem? Because in the moment also then the database with the already optimized images would have to be loaded, by the 2 calls.

    I have also briefly looked at the function. the description says

    @param string $file Full absolute path to the image file.

    Can I now not store a folder path there? But must specify the path directly to the file?

    • This reply was modified 1 year, 4 months ago by enkirch.
    Plugin Author nosilver4u

    (@nosilver4u)

    Yes, the ewww_image_optimizer() function will check if a given file/image has already been optimized, and it will not be a problem to call it multiple times, as it’s only looking up that specific image in the database. The table is properly indexed to minimize the performance impact of multiple lookups.

    As for the $file param, yes it must be a file path, it does not accept a directory/folder.

    Plugin Support adamewww

    (@adamewww)

    Resolving this thread, however, if you have further questions, please feel free to start a new one!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Compress manually’ is closed to new replies.