WriteBlob Failed `/tmp/5f49ac095abe6.png’ @ error/png.c/MagickPNGErrorHandler/1630

I’m developing a php7.1 app on a windows 10 pc running symfony dev server but everytime i run a script to convert a svg to png i receive this error.

WriteBlob Failed `/tmp/5f49ac095abe6.png’ @ error/png.c/MagickPNGErrorHandler/1630

I just bought this computer and the script works on my old windows laptops. I did research and suspect this is a permissions issue but I exhausted all means to change php and imagick tmp storage location.

If it is indeed a permissions issue then how can i update where php/imagick saves tmp files.

here is my entire method for reference:

private function createImageFromSVG(ConfigLogo $logoConfig)
{
    $svg = $logoConfig->getDefaultImage()->getContent();
    $idColorArray = [
        'first' => $logoConfig->getFirstColor(),
        'second' => $logoConfig->getSecondColor(),
        'third' => $logoConfig->getThirdColor(),
    ];

    foreach ($idColorArray as $state => $color) {
        if ($color != 'FFFFFF') {
            $svg = preg_replace(
                '/class="' . $state . '" style="fill:#([0-9a-fA-F]{6})/',
                'class="' . $state . '" style="fill:#' . $color,
                $svg
            );
        }
    }

    $fileName = sprintf('%s.png', uniqid());
    $filePath = sprintf('/tmp/%s', $fileName);
    $this->filePath = $filePath;

    $im = new Imagick();
    $im->setBackgroundColor(new ImagickPixel('transparent'));
    $im->readImageBlob($svg);
    $im->setImageFormat("png24");
    $im->writeImage($filePath);

    $file = new UploadedFile($filePath, $fileName .'.png');
    $im->clear();
    $im->destroy();

    $oldImages  = $logoConfig->getRenderedLogoImages();
    foreach ($oldImages as $image) {
        if ($image->getImageName() !== 'default_logo.png') {
            $this->uploadHandler->remove($image, 'imageFile');
        }
        $logoConfig->removeRenderedLogoImage($image);
    }

    $renderedImage = new ConfigLogoDefaultImage();
    $renderedImage->setImageFile($file);
    $renderedImage->setImageName($fileName);
    $logoConfig->addRenderedLogoImage($renderedImage);
    $this->operateImage($logoConfig, 'RenderedLogo');
}

The error occurs at line $im->writeImage($filePath);

Thanks in advance for any help with this.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *