Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When making use of the imagemagick toolkit and the texttowrapper operation alot in my image styles i've noticed a whole lot of temporary image_effects_*.png files being created in the temporary directory.
Now these files don't get cleaned up after applying the image effect which leads to alot of temporary files if you use this effect alot.
Comment | File | Size | Author |
---|---|---|---|
#12 | interdiff_9-12.txt | 1.64 KB | mondrake |
#12 | 3046522-12.patch | 2.43 KB | mondrake |
#9 | 3046522-9-test-only.patch | 1.71 KB | mondrake |
#9 | 3046522-9.patch | 2.48 KB | mondrake |
#2 | image_effects-3046522-2.patch | 1.29 KB | y_h |
Comments
Comment #2
y_h CreditAttribution: y_h commentedI made a patch to clean all these files up after all the processing is done.
Comment #3
mondrakeThank you. Can we add tests for this?
I think
static::class
instead of FQCN should work the same.This methods needs a more descriptive name ...
deleteTempWrapperFile
maybe?Comment #4
mondrakeComment #5
mondrakeAlso:
I think we should use
drupal_register_shutdown_function
here.and some CS issues:
Comment #6
fietserwinPerhaps do it in the effect class? This will cover any image toolkit that creates a temporary file on the fly for this effect.
Some notes:
- the needs tests remains
- file_unmanaged_delete() does handle non-existing files but creates a log entry for it, so I also do a check with file_exists() before calling file_unmanaged_delete().
Comment #7
mondrake@fietserwin unfortunately #6 won't work: the wrapper image file needs to be available for the
::save
method of the Imagemagick toolkit (when theconvert
executable is invoked), which is only called at the end of theImageStyle::createDerivative
method when all effects have been applied to the source image.Comment #8
fietserwinYes, you're right, like I did in D7 (using a hook_exit). Thu indeed back to the patch of #2.
Comment #9
mondrakeHere's #2 with a test and a test-only patch. Nothing will fail until #3046619: Introduce DrupalCI configuration to install ImageMagick and GraphicsMagick on testbots is solved, since tests for ImageMagick toolkit are currently skipped on DrupalCI testbots.
Comment #10
mondrakeNeeds work anyway for #3 and #5.
Comment #11
mondrake#3046619: Introduce DrupalCI configuration to install ImageMagick and GraphicsMagick on testbots is committed, retesting the patches in #9.
Comment #12
mondrakeAddressed #3 and #5.
Comment #13
fietserwinFine with me, though I would have used different names, see below. Commit either with or without the changes suggested, without a need to set it back to NR.
Aside: where does the name $gd_wrapper[_destination] come from? We are not in the gd toolkit.
that's => that is (like it's was changed to it has).
deleteTempFile($filename) (Wrapper in the method name does not add any clarity, $filename seems to be used in most php and Drupal file functions, though Drupal also uses $uri/$url or $path (the latter when it might also be a directory))
Comment #14
mondrakeThanks @fietserwin.
Changes on commit:
We are using the GD toolkit here, just to prepare an image with hte text inside (the wrapper) that is then overlaid via IM. Unfortunately it won't be easy to develop a native IM toolkit operation for the same with all the options that this operation has.
Comment #17
mondrakeCommitted. Thanks all.
Comment #18
fietserwinOops, a dependency on the gd library (at least not the toolkit) in the IM toolkit... :)
Comment #19
mondrakeNono, it depends on the GD toolkit actually :) Same for the Smart Crop effects.