Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rasterimage return partial image #131

Open
meravwebs opened this issue Nov 1, 2021 · 5 comments
Open

rasterimage return partial image #131

meravwebs opened this issue Nov 1, 2021 · 5 comments

Comments

@meravwebs
Copy link

i'm using this code:
$image = SVG::fromString($svg);
$doc = $image->getDocument();

$w = $doc->getWidth();
$h = $doc->getHeight();

$rasterImage = $image->toRasterImage($w, $h);

imagepng($rasterImage, $png_path);

it creates an image, but only partial.

the svg i'm using have image element in it and the image created is only part of the image element of the svg instead of the entire svg.

@jcogs-design
Copy link

jcogs-design commented Mar 2, 2022

I have this issue too... a composite SVG that includes a raster image, some gradients, shapes and a text path loads correctly (all elements are present in the SVG\SVG type object created by the SVG::fromString method), but when a raster version of the image is created, while the dimensions are correct for the whole svg source image, the only content is the embedded raster image.

Using php 7.4...

Any guidance / hints on how to resolve would be very helpful!

@meyfa
Copy link
Owner

meyfa commented Mar 2, 2022

The way to resolve this is to implement the required functionality in this library. At the moment, rendering of gradients is not supported. Text rendering is severely limited as well. In the past few weeks I have spent some time improving rasterization, such as by introducing transform support, improved path and polygon filling, style parsing and a few other details. If your SVGs make use of these features, you will see improvements with the upcoming v0.12.0 release. There is still a lot missing though. Feel free to contribute code for some of the missing features :) Otherwise, if you just need a robust solution quickly, I hear some people have had more luck with Gmagick or Imagick for converting SVG to raster formats.

@jcogs-design
Copy link

Hi

Happy to contribute if I can.

Probably would be helpful if the readme gave some better details about what the library is able to do - the currently posted information is rather vague. Clearly what is there currently is not sufficiently clear - otherwise neither @meravwebs nor I would have had the mistaken understanding that rendering of text or shapes was supported.

@meyfa
Copy link
Owner

meyfa commented Mar 2, 2022

Probably would be helpful if the readme gave some better details about what the library is able to do

Yes, I absolutely agree! Will add "summary of the current feature set" to the to-do-list in #125.

the mistaken understanding that rendering of text or shapes was supported

Actually, rendering shapes should be supported. All of the basic geometric shapes (ellipses, rectangles, polygons...) as well as paths support fill and stroke rendering. Can you provide a short sample SVG showing the stuff that doesn't work?

@jcogs-design
Copy link

Ace - look forward to seeing the summary when it is avail.

Another thing that would be useful perhaps would be your thoughts about the priorities for development.

The test image I used is attached - it is something created in Pixelmator Pro, and when rendered using the library only the embedded image is shown - the text and star shapes it includes do not get rendered.

svg_test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants