# Svg file loading distorted

**URL:** https://discourse.processing.org/t/svg-file-loading-distorted/12527
**Category:** Coding Questions
**Created:** [July 5, 2019, 3:07pm UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527 "2019-07-05T15:07:19Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Ruchi](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Ruchi](https://discourse.processing.org/u/Ruchi)
#### Post date: [July 5, 2019, 3:07pm UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527/1 "2019-07-05T15:07:20Z")

</div>

I am loading an svg file which contains numerous square shapes stacked diagonally.

I wrote a simple code  
PShape image;

void setup()  
{  
size(600,600);  
image=loadShape(“squares.svg”);

}

void draw()  
{  
shapeMode(CENTER);  
shape(image,width/2,height/2,width,height);  
saveFrame(“a.png”);  
}

It gives me something like below. The squares are misaligned with each other & the overall file is rotated too.

 ![a](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f781a868ef7d4087df337e353642ba08289c6ce9.png)

How to solve this?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [July 6, 2019, 12:19am UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527/2 "2019-07-06T00:19:30Z")

</div>

pls repair/format your posted code  
and post the SVG file you talk about.  
as a SVG file is text, you can also post it as code.

use the

```auto
</> code tag

```

looks like  
```  
type or paste code here  
```

---

<div class="post-metadata">

### Author: ![Ruchi](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Ruchi](https://discourse.processing.org/u/Ruchi)
#### Post date: [July 6, 2019, 4:33am UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527/4 "2019-07-06T04:33:36Z")

</div>

Hi here is the actual file.

```auto
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="600px" height="600px" viewBox="0 0 600 600" enable-background="new 0 0 600 600" xml:space="preserve">
<g>
	<g transform="translate(5,5) rotate(45)">
		<rect x="28.285" y="-35.355" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(5,5) rotate(45)">
		<rect x="28.285" y="-35.355" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(10,10) rotate(45)">
		<rect x="91.925" y="-35.355" fill="#818181" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(10,10) rotate(45)">
		<rect x="91.925" y="-35.355" fill="#818181" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(15,15) rotate(45)">
		<rect x="155.564" y="-35.355" fill="#818181" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(15,15) rotate(45)">
		<rect x="155.564" y="-35.355" fill="#818181" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(20,20) rotate(45)">
		<rect x="219.204" y="-35.355" fill="#818181" width="70.711" height="70.71"/>
	</g>
	<g transform="translate(20,20) rotate(45)">
		<rect x="219.204" y="-35.355" fill="#818181" width="70.711" height="70.71"/>
	</g>
	<g transform="translate(25,25) rotate(45)">
		<rect x="282.843" y="-35.355" fill="#414141" width="70.71" height="70.711"/>
	</g>
	<g transform="translate(25,25) rotate(45)">
		<rect x="282.843" y="-35.355" fill="#414141" width="70.71" height="70.711"/>
	</g>
	<g transform="translate(30,30) rotate(45)">
		<rect x="346.483" y="-35.355" fill="#414141" width="70.71" height="70.711"/>
	</g>
	<g transform="translate(30,30) rotate(45)">
		<rect x="346.483" y="-35.355" fill="#414141" width="70.71" height="70.711"/>
	</g>
	<g transform="translate(35,35) rotate(45)">
		<rect x="410.123" y="-35.355" fill="#414141" width="70.71" height="70.711"/>
	</g>
	<g transform="translate(35,35) rotate(45)">
		<rect x="410.123" y="-35.355" fill="#414141" width="70.71" height="70.711"/>
	</g>
	<g transform="translate(40,40) rotate(45)">
		<rect x="473.76" y="-35.355" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(40,40) rotate(45)">
		<rect x="473.76" y="-35.355" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(45,45) rotate(45)">
		<rect x="537.401" y="-35.355" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(45,45) rotate(45)">
		<rect x="537.401" y="-35.355" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(50,50) rotate(45)">
		<rect x="601.041" y="-35.355" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(50,50) rotate(45)">
		<rect x="601.041" y="-35.355" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(55,55) rotate(45)">
		<rect x="664.679" y="-35.355" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(15,5) rotate(45)">
		<rect x="91.925" y="-98.995" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(5,15) rotate(45)">
		<rect x="91.925" y="28.284" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(20,10) rotate(45)">
		<rect x="155.564" y="-98.995" fill="#818181" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(10,20) rotate(45)">
		<rect x="155.564" y="28.284" fill="#818181" width="70.711" height="70.71"/>
	</g>
	<g transform="translate(25,15) rotate(45)">
		<rect x="219.204" y="-98.995" fill="#818181" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(15,25) rotate(45)">
		<rect x="219.204" y="28.284" fill="#414141" width="70.71" height="70.711"/>
	</g>
	<g transform="translate(30,20) rotate(45)">
		<rect x="282.842" y="-98.995" fill="#818181" width="70.71" height="70.71"/>
	</g>
	<g transform="translate(20,30) rotate(45)">
		<rect x="282.843" y="28.284" fill="#818181" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(35,25) rotate(45)">
		<rect x="346.483" y="-98.995" fill="#414141" width="70.71" height="70.711"/>
	</g>
	<g transform="translate(25,35) rotate(45)">
		<rect x="346.483" y="28.284" fill="#010101" width="70.711" height="70.712"/>
	</g>
	<g transform="translate(40,30) rotate(45)">
		<rect x="410.122" y="-98.995" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(30,40) rotate(45)">
		<rect x="410.123" y="28.284" fill="#414141" width="70.71" height="70.71"/>
	</g>
	<g transform="translate(45,35) rotate(45)">
		<rect x="473.762" y="-98.995" fill="#010101" width="70.711" height="70.712"/>
	</g>
	<g transform="translate(35,45) rotate(45)">
		<rect x="473.762" y="28.284" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(50,40) rotate(45)">
		<rect x="537.401" y="-98.995" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(40,50) rotate(45)">
		<rect x="537.401" y="28.284" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(55,45) rotate(45)">
		<rect x="601.041" y="-98.995" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(45,55) rotate(45)">
		<rect x="601.04" y="28.284" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(25,5) rotate(45)">
		<rect x="155.564" y="-162.635" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(5,25) rotate(45)">
		<rect x="155.564" y="91.924" fill="#010101" width="70.71" height="70.711"/>
	</g>
	<g transform="translate(30,10) rotate(45)">
		<rect x="219.204" y="-162.634" fill="#414141" width="70.71" height="70.71"/>
	</g>
	<g transform="translate(10,30) rotate(45)">
		<rect x="219.204" y="91.924" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(35,15) rotate(45)">
		<rect x="282.843" y="-162.634" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(15,35) rotate(45)">
		<rect x="282.843" y="91.924" fill="#414141" width="70.711" height="70.712"/>
	</g>
	<g transform="translate(40,20) rotate(45)">
		<rect x="346.483" y="-162.634" fill="#414141" width="70.711" height="70.71"/>
	</g>
	<g transform="translate(20,40) rotate(45)">
		<rect x="346.483" y="91.924" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(45,25) rotate(45)">
		<rect x="410.122" y="-162.634" fill="#414141" width="70.71" height="70.711"/>
	</g>
	<g transform="translate(25,45) rotate(45)">
		<rect x="410.122" y="91.924" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(50,30) rotate(45)">
		<rect x="473.762" y="-162.635" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(30,50) rotate(45)">
		<rect x="473.761" y="91.924" fill="#010101" width="70.711" height="70.71"/>
	</g>
	<g transform="translate(55,35) rotate(45)">
		<rect x="537.401" y="-162.635" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(35,55) rotate(45)">
		<rect x="537.401" y="91.924" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(35,5) rotate(45)">
		<rect x="219.203" y="-226.274" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(5,35) rotate(45)">
		<rect x="219.204" y="155.563" fill="#010101" width="70.71" height="70.711"/>
	</g>
	<g transform="translate(40,10) rotate(45)">
		<rect x="282.843" y="-226.274" fill="#818181" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(10,40) rotate(45)">
		<rect x="282.843" y="155.563" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(45,15) rotate(45)">
		<rect x="346.482" y="-226.274" fill="#414141" width="70.712" height="70.711"/>
	</g>
	<g transform="translate(15,45) rotate(45)">
		<rect x="346.483" y="155.563" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(50,20) rotate(45)">
		<rect x="410.122" y="-226.274" fill="#414141" width="70.711" height="70.71"/>
	</g>
	<g transform="translate(20,50) rotate(45)">
		<rect x="410.122" y="155.563" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(55,25) rotate(45)">
		<rect x="473.761" y="-226.274" fill="#414141" width="70.71" height="70.711"/>
	</g>
	<g transform="translate(25,55) rotate(45)">
		<rect x="473.762" y="155.563" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(45,5) rotate(45)">
		<rect x="282.843" y="-289.913" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(5,45) rotate(45)">
		<rect x="282.843" y="219.203" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(50,10) rotate(45)">
		<rect x="346.483" y="-289.913" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(10,50) rotate(45)">
		<rect x="346.482" y="219.203" fill="#414141" width="70.712" height="70.711"/>
	</g>
	<g transform="translate(55,15) rotate(45)">
		<rect x="410.122" y="-289.913" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(15,55) rotate(45)">
		<rect x="410.122" y="219.203" fill="#414141" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(55,5) rotate(45)">
		<rect x="346.483" y="-353.553" fill="#010101" width="70.711" height="70.711"/>
	</g>
	<g transform="translate(5,55) rotate(45)">
		<rect x="346.483" y="282.842" fill="#414141" width="70.711" height="70.711"/>
	</g>
</g>
</svg>

```

in png format

 ![squares](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1082dd8685e1d29981d42b75837120bcbe8f66d0.png)  
thanks.

---

<div class="post-metadata">

### Author: ![Ruchi](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Ruchi](https://discourse.processing.org/u/Ruchi)
#### Post date: [July 6, 2019, 4:39am UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527/5 "2019-07-06T04:39:41Z")

</div>

DISTORTED FILE

```auto
<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
          'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg xmlns:xlink="http://www.w3.org/1999/xlink" style="fill-opacity:1; color-rendering:auto; color-interpolation:auto; text-rendering:auto; stroke:black; stroke-linecap:square; stroke-miterlimit:10; shape-rendering:auto; stroke-opacity:1; fill:black; stroke-dasharray:none; font-weight:normal; stroke-width:1; font-family:'Dialog'; font-style:normal; stroke-linejoin:miter; font-size:12px; stroke-dashoffset:0; image-rendering:auto;" width="600" height="600" xmlns="http://www.w3.org/2000/svg"
><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"
  /><g
  ><g style="fill:rgb(65,65,65); stroke:rgb(65,65,65);" transform="scale(0.871,0.871) matrix(0.5253,0.8509,-0.8509,0.5253,5,5)"
    ><rect x="28.285" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,4.3552,4.3552)"
    ><rect x="28.285" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(129,129,129); stroke-linecap:round; stroke:rgb(129,129,129);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,8.7105,8.7105)"
    ><rect x="91.925" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(129,129,129); stroke-linecap:round; stroke:rgb(129,129,129);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,8.7105,8.7105)"
    ><rect x="91.925" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(129,129,129); stroke-linecap:round; stroke:rgb(129,129,129);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,13.0657,13.0657)"
    ><rect x="155.564" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(129,129,129); stroke-linecap:round; stroke:rgb(129,129,129);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,13.0657,13.0657)"
    ><rect x="155.564" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(129,129,129); stroke-linecap:round; stroke:rgb(129,129,129);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,17.421,17.421)"
    ><rect x="219.204" width="70.711" height="70.71" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(129,129,129); stroke-linecap:round; stroke:rgb(129,129,129);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,17.421,17.421)"
    ><rect x="219.204" width="70.711" height="70.71" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,21.7762,21.7762)"
    ><rect x="282.843" width="70.71" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,21.7762,21.7762)"
    ><rect x="282.843" width="70.71" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,26.1315,26.1315)"
    ><rect x="346.483" width="70.71" height="70.71" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,26.1315,26.1315)"
    ><rect x="346.483" width="70.71" height="70.71" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,30.4867,30.4867)"
    ><rect x="410.122" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,30.4867,30.4867)"
    ><rect x="410.122" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,34.8419,34.8419)"
    ><rect x="473.761" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,34.8419,34.8419)"
    ><rect x="473.761" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,39.1972,39.1972)"
    ><rect x="537.401" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,39.1972,39.1972)"
    ><rect x="537.401" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,43.5524,43.5524)"
    ><rect x="601.041" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,43.5524,43.5524)"
    ><rect x="601.041" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,47.9077,47.9077)"
    ><rect x="664.68" width="70.711" height="70.711" y="-35.355" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,13.0657,4.3552)"
    ><rect x="91.925" width="70.711" height="70.711" y="-98.995" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,4.3552,13.0657)"
    ><rect x="91.925" width="70.711" height="70.711" y="28.284" style="stroke:none;"
    /></g
    ><g style="fill:rgb(129,129,129); stroke-linecap:round; stroke:rgb(129,129,129);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,17.421,8.7105)"
    ><rect x="155.564" width="70.711" height="70.711" y="-98.995" style="stroke:none;"
    /></g
    ><g style="fill:rgb(129,129,129); stroke-linecap:round; stroke:rgb(129,129,129);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,8.7105,17.421)"
    ><rect x="155.564" width="70.711" height="70.71" y="28.284" style="stroke:none;"
    /></g
    ><g style="fill:rgb(129,129,129); stroke-linecap:round; stroke:rgb(129,129,129);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,21.7762,13.0657)"
    ><rect x="219.204" width="70.711" height="70.711" y="-98.995" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,13.0657,21.7762)"
    ><rect x="219.204" width="70.71" height="70.711" y="28.284" style="stroke:none;"
    /></g
    ><g style="fill:rgb(129,129,129); stroke-linecap:round; stroke:rgb(129,129,129);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,26.1315,17.421)"
    ><rect x="282.843" width="70.71" height="70.71" y="-98.995" style="stroke:none;"
    /></g
    ><g style="fill:rgb(129,129,129); stroke-linecap:round; stroke:rgb(129,129,129);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,17.421,26.1315)"
    ><rect x="282.843" width="70.711" height="70.711" y="28.284" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,30.4867,21.7762)"
    ><rect x="346.483" width="70.71" height="70.711" y="-98.995" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,21.7762,30.4867)"
    ><rect x="346.483" width="70.711" height="70.711" y="28.284" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,34.8419,26.1315)"
    ><rect x="410.122" width="70.711" height="70.711" y="-98.995" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,26.1315,34.8419)"
    ><rect x="410.123" width="70.71" height="70.71" y="28.284" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,39.1972,30.4867)"
    ><rect x="473.762" width="70.711" height="70.711" y="-98.995" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,30.4867,39.1972)"
    ><rect x="473.762" width="70.711" height="70.711" y="28.284" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,43.5524,34.8419)"
    ><rect x="537.401" width="70.711" height="70.711" y="-98.995" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,34.8419,43.5524)"
    ><rect x="537.401" width="70.711" height="70.711" y="28.284" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,47.9077,39.1972)"
    ><rect x="601.041" width="70.711" height="70.711" y="-98.995" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,39.1972,47.9077)"
    ><rect x="601.041" width="70.711" height="70.711" y="28.284" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,21.7762,4.3552)"
    ><rect x="155.564" width="70.711" height="70.711" y="-162.635" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,4.3552,21.7762)"
    ><rect x="155.564" width="70.71" height="70.711" y="91.924" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,26.1315,8.7105)"
    ><rect x="219.204" width="70.71" height="70.71" y="-162.634" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,8.7105,26.1315)"
    ><rect x="219.204" width="70.711" height="70.711" y="91.924" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,30.4867,13.0657)"
    ><rect x="282.843" width="70.711" height="70.711" y="-162.634" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,13.0657,30.4867)"
    ><rect x="282.843" width="70.711" height="70.711" y="91.924" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,34.8419,17.421)"
    ><rect x="346.483" width="70.711" height="70.71" y="-162.634" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,17.421,34.8419)"
    ><rect x="346.483" width="70.711" height="70.711" y="91.924" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,39.1972,21.7762)"
    ><rect x="410.122" width="70.71" height="70.711" y="-162.634" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,21.7762,39.1972)"
    ><rect x="410.122" width="70.711" height="70.711" y="91.924" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,43.5524,26.1315)"
    ><rect x="473.762" width="70.711" height="70.711" y="-162.635" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,26.1315,43.5524)"
    ><rect x="473.762" width="70.71" height="70.71" y="91.924" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,47.9077,30.4867)"
    ><rect x="537.401" width="70.711" height="70.711" y="-162.635" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,30.4867,47.9077)"
    ><rect x="537.401" width="70.711" height="70.711" y="91.924" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,30.4867,4.3552)"
    ><rect x="219.204" width="70.711" height="70.711" y="-226.274" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,4.3552,30.4867)"
    ><rect x="219.204" width="70.711" height="70.711" y="155.563" style="stroke:none;"
    /></g
    ><g style="fill:rgb(129,129,129); stroke-linecap:round; stroke:rgb(129,129,129);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,34.8419,8.7105)"
    ><rect x="282.843" width="70.711" height="70.711" y="-226.274" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,8.7105,34.8419)"
    ><rect x="282.843" width="70.711" height="70.711" y="155.563" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,39.1972,13.0657)"
    ><rect x="346.483" width="70.711" height="70.711" y="-226.274" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,13.0657,39.1972)"
    ><rect x="346.483" width="70.711" height="70.711" y="155.563" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,43.5524,17.421)"
    ><rect x="410.122" width="70.711" height="70.71" y="-226.274" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,17.421,43.5524)"
    ><rect x="410.122" width="70.711" height="70.711" y="155.563" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,47.9077,21.7762)"
    ><rect x="473.762" width="70.71" height="70.711" y="-226.274" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,21.7762,47.9077)"
    ><rect x="473.762" width="70.711" height="70.711" y="155.563" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,39.1972,4.3552)"
    ><rect x="282.843" width="70.711" height="70.711" y="-289.913" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,4.3552,39.1972)"
    ><rect x="282.843" width="70.711" height="70.711" y="219.203" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,43.5524,8.7105)"
    ><rect x="346.483" width="70.711" height="70.711" y="-289.913" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,8.7105,43.5524)"
    ><rect x="346.483" width="70.711" height="70.711" y="219.203" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,47.9077,13.0657)"
    ><rect x="410.122" width="70.711" height="70.711" y="-289.913" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,13.0657,47.9077)"
    ><rect x="410.122" width="70.711" height="70.711" y="219.203" style="stroke:none;"
    /></g
    ><g style="fill:rgb(1,1,1); stroke-linecap:round; stroke:rgb(1,1,1);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,47.9077,4.3552)"
    ><rect x="346.483" width="70.711" height="70.711" y="-353.553" style="stroke:none;"
    /></g
    ><g style="fill:rgb(65,65,65); stroke-linecap:round; stroke:rgb(65,65,65);" transform="matrix(0.4576,0.7412,-0.7412,0.4576,4.3552,47.9077)"
    ><rect x="346.483" width="70.711" height="70.711" y="282.842" style="stroke:none;"
    /></g
  ></g
></svg
>

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [July 6, 2019, 6:17am UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527/6 "2019-07-06T06:17:25Z")

</div>

not understand why you posted 2 files?  
actual and distorted,  
but yes both look same bad ( like you show already )  
as if the 45deg rotation not correct.

used code:

```auto
PShape imgsvg;
String infile = "data/squares.svg";

void setup() {
  size(600, 600);
  imgsvg=loadShape(infile);
}

void draw() {
  shape(imgsvg, 0, 0);
}

```

* * *

interestingly the “actual” file ( double click under win7 )  
shown in a browser, looks good,  
so there could be a bug in the importing to processing.

 ![SNAG-0134](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3fb4faa3c3c9a39be08d2d80de5fb8890dfe4659.jpeg)

looking at the source, both SVG have a questionable  
content ( but that is NOT the cause of the problem )  
every rectangle appears double???

when i play manually like using a single rotate:

> data/squares.svg

```auto
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: notepad ++) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="600px" height="600px" viewBox="0 0 600 600" enable-background="new 0 0 600 600" xml:space="preserve">
<g transform="translate(100,100) rotate(45)">

	<g>
		<rect x="0" y="0" fill="#414141" width="70" height="70"/>
	</g>
	<g>
		<rect x="70" y="0" fill="#818181" width="70" height="70"/>
	</g>

</g>
</svg>

```

it looks ok.

---

<div class="post-metadata">

### Author: ![Ruchi](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Ruchi](https://discourse.processing.org/u/Ruchi)
#### Post date: [July 6, 2019, 7:03am UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527/7 "2019-07-06T07:03:15Z")

</div>

I sent both the file for reference of comparison.

The actual file is made in processing itself by fetching color of pixels from an image and setting the rotating squares in processing.  
input image for code :

 ![arotated](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/609113273e888c7ec5d1c8909b6626595a8c2a57.png)

```auto
import processing.svg.*;

PGraphics pG;
PImage img;

//co-ordinates for Pgraphics image
int xW;
int yH;

// color for Pgraphics image pixels left of center column & right of width/2 center column
color c1; 
color c2;

// co-ordinates for diagonal rectangles
int xD;
int yD;
int spacing;

//variable to change yD after every diagonal line
int colyD;

// variable to identify column no. on either side of center column in image
int colG;

void setup()
{ 
  size(940, 940);
  //background(255);
  img=loadImage("arotated.png");
  pG=createGraphics(img.width, img.height);
  pG.beginDraw();
  pG.image(img, 0, 0);
  pG.endDraw();

  spacing=5;
  xD=spacing;
  yD=spacing;

  colyD= spacing;
  colG=0;

  xW=pG.width/2;
  beginRecord(SVG, "filename.svg");
  noLoop();
}

void draw()
{  
  for (int i=0; i<=93; i++)
  {
    xD=spacing;
    yD=colyD;
    for ( yH=colyD; yH<(pG.height-colG); yH+=spacing*2)
    { 
      // Getting colors for pixel left of center column and right of center column in Pgraphics image
      c1=pG.get(xW + colG, yH);
      c2=pG.get(xW - colG, yH);
      
      //Drawing rectangle below the diagonal
      push();
      translate(yD, xD);
      rotate(radians(45));
      fill(c1);
      noStroke();
      rectMode(CENTER);
      rect(0, 0, 10/1.41421356237, 10/1.41421356237);
      pop();

      //Drawing rectangle below the diagonal
      push();
      translate(xD, yD);
      rotate(radians(45));
      fill(c2);
      noStroke();
      rectMode(CENTER);
      rect(0, 0, 10/1.41421356237, 10/1.41421356237);
      pop();

      xD=xD+spacing;
      yD=yD+spacing;
    }
    colyD+=spacing*2;
    println(colyD);
    colG+=spacing*2;
  }
  endRecord();
}

```

The for loop creates double squares for the longest diagonal that is why you see the squares repeating but thats only for the longest diagonal.

I saved this file as svg. It opens proper in illustrator.

But when I reload it in the processing , it shows the distorted svg.

Earlier images where the cropped section to upload in forum.

---

<div class="post-metadata">

### Author: ![Ruchi](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Ruchi](https://discourse.processing.org/u/Ruchi)
#### Post date: [July 7, 2019, 3:29pm UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527/8 "2019-07-07T15:29:51Z")

</div>

Going through some other issues and not sure if my issue with svgs is related to the full svg implementation in processing.

The shapes are simple not compound paths so can’t seem to get around with this.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [July 7, 2019, 4:00pm UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527/9 "2019-07-07T16:00:59Z")

</div>

It seems quite likely that float precision on 45 degrees (0.785398 radians) is not sufficient to recreate your rotated squares.

Can you explain more what you are doing?

1. You have a grayscale pixelated image of a face.
2. You scaled it up and rotated it by 45 degrees in Photoshop or Gimp so that it has diamond pixels
3. Now you are importing it into Processing in order to encode those diamonds as squares, then rotate them back to diamonds…?

I’m a bit lost. What is your end goal? If your end goal is a square image with diamond pixels, then I would suggest this:

1. load the original, unrotate face gif. It is a square image with square pixels.
2. rotate(45) and draw to PGraphics
3. begin recording svg
4. sample the pixels values and draw encode to svg as a diamond-shaped image with square pixels – the svg contains no rotated elements, just rows of squares, like a checkerboard. In other words, your svg is a literal transcription of arotated.png.
5. save

Now, display:

1. load the svg
2. use translate(-img.width/2.0); rotate(radians(-45));
3. draw the svg. It is now a square image with diamond pixels that are correctly aligned.

---

<div class="post-metadata">

### Author: ![Ruchi](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Ruchi](https://discourse.processing.org/u/Ruchi)
#### Post date: [July 7, 2019, 4:34pm UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527/10 "2019-07-07T16:34:17Z")

</div>

What you are suggesting works well in other way by simply saving the file in png. That would work too!

I am working on a project where I am going to be replacing these rotated squares with lots of svg files based on the colors of squares.  
So rotated squares is mandatory I feel.

Another option I figured out is to save it as png file.Draw it in Pgraphics. Just fetch the color and redraw the squares back. This time replacing it with svg files as mentioned.  
And I would be recording this too as svg.

So if again I import it back . It would cause the same issue.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [July 7, 2019, 7:04pm UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527/11 "2019-07-07T19:04:38Z")

</div>

> [@Ruchi](#):
>
> rotated squares is mandatory I feel.

Right. That’s why I described a method that would produce an svg that can be displayed as rotated squares. Your issue is (probably) that you are placing and rotating them one at a time with insufficient precision, rather than rotating them as a set. You could also encode the top-level rotation into the svg by moving the beginRecord statement, if you want the svg itself to appear rotated. Just don’t rotate each individual square – map the order in your encoding pass within a frame of reference.

I’m still not clear on what your goals are, though. Do you care about what format you are saving before loading, for other purposes? Or is it just a data file to you?

---

<div class="post-metadata">

### Author: ![Ruchi](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Ruchi](https://discourse.processing.org/u/Ruchi)
#### Post date: [July 8, 2019, 5:49am UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527/12 "2019-07-08T05:49:15Z")

</div>

I am saving in svg. But the purpose of the diamonds is to retrieve its color and replace that diamond with SVG files of exactly same size.  
Something similar to this. The only difference is I am using vector files carrying shapes to replace the pixels.

[![](https://img.youtube.com/vi/nnlAH1zDBDE/hqdefault.jpg "Coding Challenge #49: Photo Mosaic with White House Social Media Images") ](https://www.youtube.com/watch?v=nnlAH1zDBDE)

> [@jeremydouglass](#):
>
> You could also encode the top-level rotation into the svg by moving the beginRecord statement, if you want the svg itself to appear rotated. Just don’t rotate each individual square – map the order in your encoding pass within a frame of reference.

sorry I didn’t understand this method you suggested.

Sorry but I am still not following the precision error as I made the svg file in processing itself.

---

<div class="post-metadata">

### Author: ![Ruchi](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Ruchi](https://discourse.processing.org/u/Ruchi)
#### Post date: [July 8, 2019, 6:23am UTC](https://discourse.processing.org/t/svg-file-loading-distorted/12527/13 "2019-07-08T06:23:52Z")

</div>

I am starting to realize I might not need the diamonds for replacing it with svg pattern file. Just retreiving the colors and redrawing the pattern file of same size would do the job.

But then again rotating the file would be the issue again.  
Also how to call on individual shapes from svg files.

I am little confused.
