Loading src/Plugin/ImageToolkit/Operation/imagemagick/TextToWrapper.php +16 −1 Original line number Diff line number Diff line Loading @@ -29,14 +29,29 @@ class TextToWrapper extends ImagemagickImageToolkitOperationBase { $gd_wrapper->apply('text_to_wrapper', $arguments); // Flush the temporary wrapper to disk, reopen via ImageMagick and return. if ($gd_wrapper) { $tmp_file = \Drupal::service('file_system')->tempnam('temporary://', 'image_effects_'); // Temporary file prefix is limited to 3 chars for Windows compatibility. $tmp_file = \Drupal::service('file_system')->tempnam('temporary://', 'ifx'); $gd_wrapper_destination = $tmp_file . '.png'; file_unmanaged_move($tmp_file, $gd_wrapper_destination, FILE_CREATE_DIRECTORY); $gd_wrapper->save($gd_wrapper_destination); $tmp_wrapper = \Drupal::service('image.factory')->get($gd_wrapper_destination, 'imagemagick'); // Defer removal of the temporary file to after it has been processed. drupal_register_shutdown_function([static::class, 'deleteTempFile'], $gd_wrapper_destination); return $this->getToolkit()->apply('replace_image', ['replacement_image' => $tmp_wrapper]); } return FALSE; } /** * Delete the image effect temporary file after it has been used. * * @param string $file_path * Path of the file that is about to be deleted. */ public static function deleteTempFile($file_path) { if (file_exists($file_path)) { file_unmanaged_delete($file_path); } } } tests/src/Functional/Effect/TextOverlayTest.php +6 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,12 @@ class TextOverlayTest extends ImageEffectsTestBase { ]; $this->addEffectToTestStyle($effect_config); // Check that no temporary files are left in Imagemagick. if ($toolkit_id === 'imagemagick') { $directory_scan = file_scan_directory('temporary://', '/ifx.*/'); $this->assertEquals(0, count($directory_scan)); } $test_data = [ [ 'test_file' => $this->getTestImageCopyUri('/files/image-test.png', 'simpletest'), Loading Loading
src/Plugin/ImageToolkit/Operation/imagemagick/TextToWrapper.php +16 −1 Original line number Diff line number Diff line Loading @@ -29,14 +29,29 @@ class TextToWrapper extends ImagemagickImageToolkitOperationBase { $gd_wrapper->apply('text_to_wrapper', $arguments); // Flush the temporary wrapper to disk, reopen via ImageMagick and return. if ($gd_wrapper) { $tmp_file = \Drupal::service('file_system')->tempnam('temporary://', 'image_effects_'); // Temporary file prefix is limited to 3 chars for Windows compatibility. $tmp_file = \Drupal::service('file_system')->tempnam('temporary://', 'ifx'); $gd_wrapper_destination = $tmp_file . '.png'; file_unmanaged_move($tmp_file, $gd_wrapper_destination, FILE_CREATE_DIRECTORY); $gd_wrapper->save($gd_wrapper_destination); $tmp_wrapper = \Drupal::service('image.factory')->get($gd_wrapper_destination, 'imagemagick'); // Defer removal of the temporary file to after it has been processed. drupal_register_shutdown_function([static::class, 'deleteTempFile'], $gd_wrapper_destination); return $this->getToolkit()->apply('replace_image', ['replacement_image' => $tmp_wrapper]); } return FALSE; } /** * Delete the image effect temporary file after it has been used. * * @param string $file_path * Path of the file that is about to be deleted. */ public static function deleteTempFile($file_path) { if (file_exists($file_path)) { file_unmanaged_delete($file_path); } } }
tests/src/Functional/Effect/TextOverlayTest.php +6 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,12 @@ class TextOverlayTest extends ImageEffectsTestBase { ]; $this->addEffectToTestStyle($effect_config); // Check that no temporary files are left in Imagemagick. if ($toolkit_id === 'imagemagick') { $directory_scan = file_scan_directory('temporary://', '/ifx.*/'); $this->assertEquals(0, count($directory_scan)); } $test_data = [ [ 'test_file' => $this->getTestImageCopyUri('/files/image-test.png', 'simpletest'), Loading