Skip to content

Image is not included in final file #242

@Luke-SF

Description

@Luke-SF

I'm having issues creating a png including an image: and when I run this minimal example, it is not saving the image or the text?

<?php
require 'vendor/autoload.php';

use SVG\SVG;
use SVG\Nodes\Structures\SVGDocumentFragment;
use SVG\Nodes\Embedded\SVGImage;
use SVG\Nodes\Texts\SVGText;
use SVG\Rasterization\Renderers\ImageRenderer;
use SVG\Rasterization\SVGRasterizer;

// Create a new SVG document
$svg = new SVG(100,100);
$doc = $svg->getDocument();

// Define the image parameters
$png = '/yourpathtosome.png'; // Ensure this path is correct
$x = 10;
$y = 10;
$width = 50;
$height = 50;

// Create and add the image to the document
$image = new SVGImage($png, $x, $y, $width, $height);
$doc->addChild($image);

// Optionally, add some text to verify the document structure
$text = new SVGText('Hello, SVG!', 20, 20);
$doc->addChild($text);

// Output the SVG content
#header('Content-Type: image/svg+xml');
echo $svg;
$rasterImage = $svg->toRasterImage(100, 100);
        imagepng($rasterImage, '/tmp/out.png');

This is on PHP8.4,
"meyfa/php-svg": "^0.9.1",
and gd is installed. It's outputting an empty png. The svg output looks okay.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions