How to fill with color a complex SVG image? - svg

I have an independent SVG image with no filling (fill="none").
I would like to fill it with color, but when I change fill="none" to fill="blue" for all paths, my file becomes a blueish mess:
Source SVG file: https://ufile.io/yaj33

Your SVG is not "clean". It is made up of several hundred open (ie. not closed) path elements. If you want to be able to fill your drawing easily, you'll need to make an SVG with a smaller number of closed shapes, perhaps one for the head, one for each arm and leg, and two open paths for the eyes.

Related

SVG to PDF rendering goes wrong - are there errors in my header?

I have a couple of SVG images that I want to paste together to make a big graphic.
First, let me present you with my problem:
This is one of the symbols, placed in a grid. The grid is, for convenience, with unit-less 100 distance from line to line.
If I render it to pdf, it looks like this instead:
Those symbols have a completely wrong size for the grid (They are much larger, mostly) and they are badly positioned if I use them raw.
So my treatment is, I scale them and position them correctly in relation to the grid, then I make a rectangle around them that encompasses them completely and makes the symbol-handling easier.
That rectangle is perfectly fitting to my grid. In my case, for this symbol, it is a rectangle encompassing the six squares around the symbol. I did this, because the symbol can be rotated by the user and the rotation is done from symbol point of view; any transform after the rotation is from the rotated point of view. So I made an attempt to de-couple the transformations by wrapping them.
Finally, I move the rectangle to a user-defined place and rotate it as the user wants to have it. So far, so well, it was extensively tested in google chrome and works reliably. In Google Chrome.
Now I wanted to translate it to pdf for printing. And after conversion, the symbol is placed in the wrong position.
I am guessing (as I made several tests) that the error is somewhere in my header.
Could someone of you please check the headers that I add and tell me if and where I did something wrong? For example there is a view box starting at -100, otherwise the symbol would be cut and wrongly placed. Is there another way to "rectangularize" any arbitrary symbol? Or is it generally the wrong way to do these kinds of things?
Here are the changes that I added around the svg symbol code. Innermost changes are applied first.
<!-- move the rectangle to the right place and rotate it as the user wishes-->
<g transform="translate(300.0, 400.0) rotate(0,150.0, 50.0) ">
<!-- a rectangle around the symbol, perfectly fitting to the grid-->
<svg x="0" y="0" width="300.0" height="200.0" version = '2.0'
xmlns="http://www.w3.org/2000/svg" viewBox="-100.0 0 300.0 200.0">
<!-- scaled to correct size, placed inside the grid as it should be -->
<g transform = "translate(-10.000, 73.614) scale(0.229,0.229)" >
<!-- original symbol, wrong size -->
<svg width="523" height="230" version = '2.0' xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 523 230">
.... lots of svg paths here ...
</svg>
</g>
</svg>
</g>

Adding event to svg elements in Phaser3

I have one SVG image file, having some paths. Something like:
<svg>
<g>
<path id="land" class="land" d="M108.114,402.043l0.683,1.604l-1.204.(truncated)">
<path id="ice" class="ice" d="M288.114,402.541l0.683,1.604l-1.204...........">
<path id="water" class="water" d="M038.114,402.543l0.683,1.604l-1.204........">
</g>
</svg>
I need to know which path was clicked. When I load SVG image file in Phaser using load.svg(), the event is triggered for the entire image and not just for the area (or path).
So, how can I detect which path was clicked? Any help is appreciated.
Might be using the wrong terms, but the SVG loader paints the projected SVG to a static bitmap texture. This eliminates the existence of these pathed objects. Even if you split these paths into their own SVG and layer them, the hitboxes for textures is going to be rectangular, based on the size of the texture.
If you separate these paths into their own SVGs, a more computationally expensive hitbox exists, with pixel-perfect enabled for the hitbox setup Docs Phaser3 #makePixelPerfect. This will look at the projected texture and apply a hitboxArea over the pixels that each SVG renders.
A less expensive hitbox for each SVG would be to implement a custom hit test function when the input manager tests for pointer-events. Docs Phaser3 HitAreaCallback. This is going to be more difficult, and its difficulty depends on the shape of the hitbox you are going for, and how accurate you need this hitbox to be. Basic geometries and contains methods for hit tests can be found in Phaser.Geom namespace, if those don't match your use case you would need to write/find a function yourself.

Printing wide SVG image with embedded PNG/JPG

I'm struggling to find a way of printing a wide SVG image. This is a common problem so let me explain my specific problem.
The image is wide and so I need to tile it (poster fashion) across about 5 or 6 A4 sheets (actual count not important). My first problem is that the default Print dialog in my Firefox or Chrome browsers, under Windows, do not allow me to scale the image height to fit the page height while also spreading the image width across multiple pages.
Someone else suggested using Inkscape to convert to PDF format as the Print dialog in Acrobat reader has better support for tiling. Well, it does, but Inkscape does not deal with embedded images (e.g. PNG or JPG). Worse still, it generates huge square error markers saying "Linked image not found" all over. These are also preserved in the generated PDF which makes it useless.
There are lots of online tools that claim they can convert SVG to PDF. I tried a handful and none coped with embedded images. They were simply discarded.
So, I'm basically looking for any route to print a wide SVG image onto a horizontal series of pages, and that preserves any embedded PNG/JPG images.
[Edit]
Some of the online results:
zamzar -- images discarded
cloudconvert -- simply used inkscape
convertio -- best of the bunch, but opacity ignored on images
online-convert.com -- images discarded
pdfresizer -- simply used inkscape
freefileconvert -- simply used inkscape
onlineconvertfree -- failed with basic SVG
pdfaid -- massively failed with basic SVG
[Edit 2]
Here are a few lines of code that show one of the embedded internet-based PNG references. This one is designed to provide a faint background image underneath the subsequent SVG shapes. Hence the opacity of 12%.
<defs>
<pattern id="img2" width="50%" height="100%" >
<image xlink:href="https://clipartart.com/images/tree-branch-clipart-png-4.png" x="0" y="0" width="50%" height="100%" />
</pattern>
</defs>
<rect width="100%" height="100%" fill="url(#img2)" fill-opacity="0.12" />
I've had time to experiment with this further (and so wasting printer paper by the shed-load).
1) Inkscape deliberately does not support Internet image references (e.g. http) for "security reasons". As mentioned, it puts a horrible error marker in the view of the loaded SVG and I have found no way to edit it out. Hence, it gets saved in any PDF version.
2) If I download local copies of the images and change their http:// references to equivalent file:/// (yes, 3 slashes) then they are accepted.
3) This allows a PDF copy to be saved, but if any of the images had an opacity (e.g. a background image) then that gets lost and it is full opacity in the PDF. This may be a conversion issue or a PDF limitation -- I do not know.
4) Since I then have local copies of the images, they can be changed to implement any faintness required "at source".
5) The Acrobat Print dialog has a Poster option for tiling the pages of a wide image. Ensuring no 'cut marks' or 'labels' are added, you can set a 'Tile scale' that keeps the height within one page, and it will spread it over as many pages as necessary for the width. On the basis of the scaling, it selects landscape/portrait itself and ignores any selection of your own.
So, problems? Yes, the Acrobat 'Overlap' setting is a mystery, leaving a thin white margin on either one or both of adjoining sheets in the output. I have not been able to correlate the width of this margin, or the appearance on one or both sheets, with this setting.
Via the Preferences button, I can get to the normal printer preferences dialog, where I can request 'Borderless printing'. Rather than fixing the issue, this just makes the correlations even more mysterious.

Using SVG and getting the path data points

I am trying to get the path data points from an SVG file I am creating for an image-map. The code should look like the below after I save to an SVG file:
<svg height="210" width="400">
<path d="M150 0 L75 200 L225 200 Z" />
</svg>
However, when saving and/or exporting the file, I am getting a bunch of gibberish instead of data points and it looks like the below:
<image id="image4125" opacity=".5" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAO4AAAEUCAYAAAAskArpAAAACXBIWXMAABYlAAAWJQFJUiTwAAAA GXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAJYNJREFUeNrsnQd8FNX2x6dsb9nN 7qb3SrqU0ATpIcEnIA9QKRZEUB/6pINYEFFqDH8bwkOeFJGm0t5LqIbewZBAIKQXAtlNdtO37z83...
I have tried using both Adobe Illustrator CC and Inkscape. Any idea how to extract the correct data points using either of these programs, or why I am getting gibberish instead of the data points? I have followed multiple instructions on different websites (including this thread on StackOverflow).
Right now I can get data points to make a rectangle of each area, but the rectangular data points overlap and conflict with other. I am trying to create a polygon path and extract the data points so each shape is unique. Any help is much appreciated.
After a week of research and many tears shed, I finally found the solution. To create SVG images with the path data included when using Adobe Photoshop and Illustrator CC, follow these instructions:
Cut up your image using Photoshop with layers of the image. Save the file as .psd.
Open .psd file in Illustrator. You will then be able to select the different images you cut up in Photoshop.
Select a single image. Open up image trace and trace the image using the Silhouettes preset option.
Click on the Expand button (you will notice the silhouette of your image now has points around the edges; these are your data points).
Open up the color palette. Make the top color white with a red line through it (this removes the fill of the silhouette). Then make the bottom color black (this traces over the trace line between the points).
Finally, on the Attributes panel, you will want to set the image map to Polygon (you can add a new to the attribute below if wanted).
After you repeat these steps over each image layer, you will then save the file as an .svg file with the following settings:
• SVG Profiles: SVG 1.1
• Subsetting: None
• Image location: Link
• Preserve Illustrator Editing Capabilities: unchecked (this will reduce the size of your file for better performance.
• CSS Properties: Style Elements
• Output fewer tspan elements: checked
• Use textPath elements for the text on path: checked
• Responsive: checked
After the file is saved with these options, you will then be able to open the .svg in Sublime, WebStorm, TextEdit, etc., and the path data will be included in the HTML. It is a beautiful sight! Hope this helps whoever is seeking the answer to my same problem!

How to place the same path multiple times at different sizes/coordinates?

I have a path I've created in Illustrator and saved as an SVG.
Now I want to programmatically place it at different sizes and coordinates on a large canvas.
Say I've got this image:
(source: omgtldr.com)
How would I reproduce that same image in different places and sizes in one SVG file, like this:
(source: omgtldr.com)
for example, one version shrunk by 20% at coordinates x,y; another enlarged by 30% at coordinates a,b and so on.
Please assume I'm going to be OK with the programming part, I'm comfortable working with XML files. It's the SVG parts I don't understand.
You need the transform attribute. You can move your paths with translate and resize them with scale.
Better to use the <use> element (transformed) than to copy your path for each instance.

Resources