How can I scale a raster image to user space units in SVG?
My Question
Given a raster image where I know how many pixels (px) correspond to a centimeter (cm) and an SVG path where I define the userspace units to be millimeters inside a viewbox that depends on the browser width: How can I scale the image so that it always has the same pixel per centimeter ratio as the SVG path?
Background
I have raster images that represent fabric textures that I want to match with svg shapes that represent a part of a piece of clothing. I want to overlay the fabric on top of the shape and for it took realistic the proportions of the shape and of the image have to match. This is all done dynamically meaning I want to solve this for the general case not just for one specific image and shape combination.
Example
I've adapted my generic and general code to this specific JS Fiddle to illustrate the problem and show my progress so far as well as where I am stuck:
http://jsfiddle.net/nx3vrz94/16/
<svg id="svgView-1" style="width:90vw" viewBox="0 0 635 334" >
<path fill-opacity="1" fill="url(#fabric1001)" d="M0 0 L635 0 L334 290 Z " id="1"></path>
<!--
Image: 1440x1080
horizontally:
2,5 cm = 51 pixel
= 20,4 pixel per cm
-->
<defs>
<pattern id="fabric1001"
patternContentUnits="objectBoundingBox"
viewBox="0 0 1 1"
preserveAspectRatio="xMidYMid slice"
width="100%" height="100%">
<image xlink:href="https://cdn.shopify.com/s/files/1/0081/1076/8185/products/3.jpg?v=1540031315"
x="0" y="0"
width="1"
height="1"
preserveAspectRatio="xMidYMid slice" />
</pattern>
</defs>
</svg>
So far I managed to add the image as a pattern and then fill the shape with an URL reference. What I don't understand is how I can tell SVG that 20.4 pixels in that image correspond to 10 user space units?
image svg
add a comment |
My Question
Given a raster image where I know how many pixels (px) correspond to a centimeter (cm) and an SVG path where I define the userspace units to be millimeters inside a viewbox that depends on the browser width: How can I scale the image so that it always has the same pixel per centimeter ratio as the SVG path?
Background
I have raster images that represent fabric textures that I want to match with svg shapes that represent a part of a piece of clothing. I want to overlay the fabric on top of the shape and for it took realistic the proportions of the shape and of the image have to match. This is all done dynamically meaning I want to solve this for the general case not just for one specific image and shape combination.
Example
I've adapted my generic and general code to this specific JS Fiddle to illustrate the problem and show my progress so far as well as where I am stuck:
http://jsfiddle.net/nx3vrz94/16/
<svg id="svgView-1" style="width:90vw" viewBox="0 0 635 334" >
<path fill-opacity="1" fill="url(#fabric1001)" d="M0 0 L635 0 L334 290 Z " id="1"></path>
<!--
Image: 1440x1080
horizontally:
2,5 cm = 51 pixel
= 20,4 pixel per cm
-->
<defs>
<pattern id="fabric1001"
patternContentUnits="objectBoundingBox"
viewBox="0 0 1 1"
preserveAspectRatio="xMidYMid slice"
width="100%" height="100%">
<image xlink:href="https://cdn.shopify.com/s/files/1/0081/1076/8185/products/3.jpg?v=1540031315"
x="0" y="0"
width="1"
height="1"
preserveAspectRatio="xMidYMid slice" />
</pattern>
</defs>
</svg>
So far I managed to add the image as a pattern and then fill the shape with an URL reference. What I don't understand is how I can tell SVG that 20.4 pixels in that image correspond to 10 user space units?
image svg
1
The way you use the pattern, its content is never repeated (never shown more than once). Do you expect to use it in a way that repetitions could happen? Your example image would not be suitable for such a use.
– ccprog
Nov 14 '18 at 16:43
@ccprog thanks for your comment. the sample image is just that, a test image I can use to get this correct. For real usage, the images will be better all alround and won't contain the calibration pattern. I don't think I'll be using tiling, as it stands now each image is larger in real space then any of the paths would ever be(if that makes sense)
– Wulf
Nov 14 '18 at 18:32
add a comment |
My Question
Given a raster image where I know how many pixels (px) correspond to a centimeter (cm) and an SVG path where I define the userspace units to be millimeters inside a viewbox that depends on the browser width: How can I scale the image so that it always has the same pixel per centimeter ratio as the SVG path?
Background
I have raster images that represent fabric textures that I want to match with svg shapes that represent a part of a piece of clothing. I want to overlay the fabric on top of the shape and for it took realistic the proportions of the shape and of the image have to match. This is all done dynamically meaning I want to solve this for the general case not just for one specific image and shape combination.
Example
I've adapted my generic and general code to this specific JS Fiddle to illustrate the problem and show my progress so far as well as where I am stuck:
http://jsfiddle.net/nx3vrz94/16/
<svg id="svgView-1" style="width:90vw" viewBox="0 0 635 334" >
<path fill-opacity="1" fill="url(#fabric1001)" d="M0 0 L635 0 L334 290 Z " id="1"></path>
<!--
Image: 1440x1080
horizontally:
2,5 cm = 51 pixel
= 20,4 pixel per cm
-->
<defs>
<pattern id="fabric1001"
patternContentUnits="objectBoundingBox"
viewBox="0 0 1 1"
preserveAspectRatio="xMidYMid slice"
width="100%" height="100%">
<image xlink:href="https://cdn.shopify.com/s/files/1/0081/1076/8185/products/3.jpg?v=1540031315"
x="0" y="0"
width="1"
height="1"
preserveAspectRatio="xMidYMid slice" />
</pattern>
</defs>
</svg>
So far I managed to add the image as a pattern and then fill the shape with an URL reference. What I don't understand is how I can tell SVG that 20.4 pixels in that image correspond to 10 user space units?
image svg
My Question
Given a raster image where I know how many pixels (px) correspond to a centimeter (cm) and an SVG path where I define the userspace units to be millimeters inside a viewbox that depends on the browser width: How can I scale the image so that it always has the same pixel per centimeter ratio as the SVG path?
Background
I have raster images that represent fabric textures that I want to match with svg shapes that represent a part of a piece of clothing. I want to overlay the fabric on top of the shape and for it took realistic the proportions of the shape and of the image have to match. This is all done dynamically meaning I want to solve this for the general case not just for one specific image and shape combination.
Example
I've adapted my generic and general code to this specific JS Fiddle to illustrate the problem and show my progress so far as well as where I am stuck:
http://jsfiddle.net/nx3vrz94/16/
<svg id="svgView-1" style="width:90vw" viewBox="0 0 635 334" >
<path fill-opacity="1" fill="url(#fabric1001)" d="M0 0 L635 0 L334 290 Z " id="1"></path>
<!--
Image: 1440x1080
horizontally:
2,5 cm = 51 pixel
= 20,4 pixel per cm
-->
<defs>
<pattern id="fabric1001"
patternContentUnits="objectBoundingBox"
viewBox="0 0 1 1"
preserveAspectRatio="xMidYMid slice"
width="100%" height="100%">
<image xlink:href="https://cdn.shopify.com/s/files/1/0081/1076/8185/products/3.jpg?v=1540031315"
x="0" y="0"
width="1"
height="1"
preserveAspectRatio="xMidYMid slice" />
</pattern>
</defs>
</svg>
So far I managed to add the image as a pattern and then fill the shape with an URL reference. What I don't understand is how I can tell SVG that 20.4 pixels in that image correspond to 10 user space units?
image svg
image svg
asked Nov 14 '18 at 14:36
WulfWulf
14818
14818
1
The way you use the pattern, its content is never repeated (never shown more than once). Do you expect to use it in a way that repetitions could happen? Your example image would not be suitable for such a use.
– ccprog
Nov 14 '18 at 16:43
@ccprog thanks for your comment. the sample image is just that, a test image I can use to get this correct. For real usage, the images will be better all alround and won't contain the calibration pattern. I don't think I'll be using tiling, as it stands now each image is larger in real space then any of the paths would ever be(if that makes sense)
– Wulf
Nov 14 '18 at 18:32
add a comment |
1
The way you use the pattern, its content is never repeated (never shown more than once). Do you expect to use it in a way that repetitions could happen? Your example image would not be suitable for such a use.
– ccprog
Nov 14 '18 at 16:43
@ccprog thanks for your comment. the sample image is just that, a test image I can use to get this correct. For real usage, the images will be better all alround and won't contain the calibration pattern. I don't think I'll be using tiling, as it stands now each image is larger in real space then any of the paths would ever be(if that makes sense)
– Wulf
Nov 14 '18 at 18:32
1
1
The way you use the pattern, its content is never repeated (never shown more than once). Do you expect to use it in a way that repetitions could happen? Your example image would not be suitable for such a use.
– ccprog
Nov 14 '18 at 16:43
The way you use the pattern, its content is never repeated (never shown more than once). Do you expect to use it in a way that repetitions could happen? Your example image would not be suitable for such a use.
– ccprog
Nov 14 '18 at 16:43
@ccprog thanks for your comment. the sample image is just that, a test image I can use to get this correct. For real usage, the images will be better all alround and won't contain the calibration pattern. I don't think I'll be using tiling, as it stands now each image is larger in real space then any of the paths would ever be(if that makes sense)
– Wulf
Nov 14 '18 at 18:32
@ccprog thanks for your comment. the sample image is just that, a test image I can use to get this correct. For real usage, the images will be better all alround and won't contain the calibration pattern. I don't think I'll be using tiling, as it stands now each image is larger in real space then any of the paths would ever be(if that makes sense)
– Wulf
Nov 14 '18 at 18:32
add a comment |
1 Answer
1
active
oldest
votes
Make your life easier and do not try to first fit an image into a pattern, and then to fit that pattern repeatedly (at least conceptually) into a path, so that you have a total of three implicit size transformations to keep track of, when all you need is to size the image correctly.
If I understand you correctly, your userspace units should equal 1mm. Then, when
- 2.04 image pixel equals 1mm equals 1 userspace unit
- your image needs to be scaled by 1 / 2.04
- making your image scale from 1440 × 1080 to 706 × 529 (rounded, the
preserveAspectRatio
will take care of the rest)
Instead of fitting a "pattern" fill inside the path, you can also cut the path shape out of the image with a clip-path. - It is actually the same process as cutting a part out of a cloth, btw…
<svg id="svgView-1" style="width:90vw" viewBox="0 0 635 334" >
<clipPath id="clip">
<path d="M0 0 L635 0 L334 290 Z "></path>
</clipPath>
<image xlink:href="https://cdn.shopify.com/s/files/1/0081/1076/8185/products/3.jpg?v=1540031315"
x="0" y="0"
width="706" height="529"
preserveAspectRatio="xMidYMid slice"
clip-path="url(#clip)"/>
</svg>
thank you for this answer. I like your idea of not doing so many size transformations. Unfortunately, I think your proposed solution doesn't quite work the way I need it to. When I open this in fullscreen, I get different pixel per cm values for the path (22.7) than for the fabric raster image (21.6). Scaling the svg together with the path element when the viewsize changes is, unfortunately, a hard requirement.
– Wulf
Nov 15 '18 at 8:17
The reason for using the path fill is that I want to display the empty path and then the user can select a fabric to fill it. A picture say more than a thousand words so I made a screenshot off the whole app sofar: imgur.com/a/3gTSZ9g
– Wulf
Nov 15 '18 at 8:19
1
Frankly, I don't understand your requirement. "Scaling the svg together with the path element" seemed to indicate: Whatever size the SVG is displayed at, each detail of the image should remain at the same place relative to the outline of the path. That is what happens. How do you compute those "pixel per cm" values?
– ccprog
Nov 15 '18 at 13:46
sorry, apparantly I misspoke, I mean the path element and the raster image should always be scaled the same way meaning that any length in real world units such as 2,5 cm should correspond to the same amount of pixels in both the path and in the raster image. Correspondingly, I get the pixel per cm value for the path by taking it's pixel width and dividing it by it's width in cm (user space units / 10). For the raster image, I measure the width in pixels that one black square takes up and divide the amount by it's known real world width of 2,5 cm.
– Wulf
Nov 16 '18 at 9:45
1
Then I can't reproduce your numbers. For me, if I change the scale of the grafic on the screen, the position of the image never changes in relation to the path. What is shown in the upper left corner, remains in the upper left corner, same as for right and bottom. The distances between the three corners always represent the same real-world distances and are taken up always by the same amount of image content. Aspect ratio is preserved, so all measurements are scaled with the same factor. As far as I can see, that is exactly what you asked for.
– ccprog
Nov 16 '18 at 13:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302668%2fhow-can-i-scale-a-raster-image-to-user-space-units-in-svg%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Make your life easier and do not try to first fit an image into a pattern, and then to fit that pattern repeatedly (at least conceptually) into a path, so that you have a total of three implicit size transformations to keep track of, when all you need is to size the image correctly.
If I understand you correctly, your userspace units should equal 1mm. Then, when
- 2.04 image pixel equals 1mm equals 1 userspace unit
- your image needs to be scaled by 1 / 2.04
- making your image scale from 1440 × 1080 to 706 × 529 (rounded, the
preserveAspectRatio
will take care of the rest)
Instead of fitting a "pattern" fill inside the path, you can also cut the path shape out of the image with a clip-path. - It is actually the same process as cutting a part out of a cloth, btw…
<svg id="svgView-1" style="width:90vw" viewBox="0 0 635 334" >
<clipPath id="clip">
<path d="M0 0 L635 0 L334 290 Z "></path>
</clipPath>
<image xlink:href="https://cdn.shopify.com/s/files/1/0081/1076/8185/products/3.jpg?v=1540031315"
x="0" y="0"
width="706" height="529"
preserveAspectRatio="xMidYMid slice"
clip-path="url(#clip)"/>
</svg>
thank you for this answer. I like your idea of not doing so many size transformations. Unfortunately, I think your proposed solution doesn't quite work the way I need it to. When I open this in fullscreen, I get different pixel per cm values for the path (22.7) than for the fabric raster image (21.6). Scaling the svg together with the path element when the viewsize changes is, unfortunately, a hard requirement.
– Wulf
Nov 15 '18 at 8:17
The reason for using the path fill is that I want to display the empty path and then the user can select a fabric to fill it. A picture say more than a thousand words so I made a screenshot off the whole app sofar: imgur.com/a/3gTSZ9g
– Wulf
Nov 15 '18 at 8:19
1
Frankly, I don't understand your requirement. "Scaling the svg together with the path element" seemed to indicate: Whatever size the SVG is displayed at, each detail of the image should remain at the same place relative to the outline of the path. That is what happens. How do you compute those "pixel per cm" values?
– ccprog
Nov 15 '18 at 13:46
sorry, apparantly I misspoke, I mean the path element and the raster image should always be scaled the same way meaning that any length in real world units such as 2,5 cm should correspond to the same amount of pixels in both the path and in the raster image. Correspondingly, I get the pixel per cm value for the path by taking it's pixel width and dividing it by it's width in cm (user space units / 10). For the raster image, I measure the width in pixels that one black square takes up and divide the amount by it's known real world width of 2,5 cm.
– Wulf
Nov 16 '18 at 9:45
1
Then I can't reproduce your numbers. For me, if I change the scale of the grafic on the screen, the position of the image never changes in relation to the path. What is shown in the upper left corner, remains in the upper left corner, same as for right and bottom. The distances between the three corners always represent the same real-world distances and are taken up always by the same amount of image content. Aspect ratio is preserved, so all measurements are scaled with the same factor. As far as I can see, that is exactly what you asked for.
– ccprog
Nov 16 '18 at 13:34
add a comment |
Make your life easier and do not try to first fit an image into a pattern, and then to fit that pattern repeatedly (at least conceptually) into a path, so that you have a total of three implicit size transformations to keep track of, when all you need is to size the image correctly.
If I understand you correctly, your userspace units should equal 1mm. Then, when
- 2.04 image pixel equals 1mm equals 1 userspace unit
- your image needs to be scaled by 1 / 2.04
- making your image scale from 1440 × 1080 to 706 × 529 (rounded, the
preserveAspectRatio
will take care of the rest)
Instead of fitting a "pattern" fill inside the path, you can also cut the path shape out of the image with a clip-path. - It is actually the same process as cutting a part out of a cloth, btw…
<svg id="svgView-1" style="width:90vw" viewBox="0 0 635 334" >
<clipPath id="clip">
<path d="M0 0 L635 0 L334 290 Z "></path>
</clipPath>
<image xlink:href="https://cdn.shopify.com/s/files/1/0081/1076/8185/products/3.jpg?v=1540031315"
x="0" y="0"
width="706" height="529"
preserveAspectRatio="xMidYMid slice"
clip-path="url(#clip)"/>
</svg>
thank you for this answer. I like your idea of not doing so many size transformations. Unfortunately, I think your proposed solution doesn't quite work the way I need it to. When I open this in fullscreen, I get different pixel per cm values for the path (22.7) than for the fabric raster image (21.6). Scaling the svg together with the path element when the viewsize changes is, unfortunately, a hard requirement.
– Wulf
Nov 15 '18 at 8:17
The reason for using the path fill is that I want to display the empty path and then the user can select a fabric to fill it. A picture say more than a thousand words so I made a screenshot off the whole app sofar: imgur.com/a/3gTSZ9g
– Wulf
Nov 15 '18 at 8:19
1
Frankly, I don't understand your requirement. "Scaling the svg together with the path element" seemed to indicate: Whatever size the SVG is displayed at, each detail of the image should remain at the same place relative to the outline of the path. That is what happens. How do you compute those "pixel per cm" values?
– ccprog
Nov 15 '18 at 13:46
sorry, apparantly I misspoke, I mean the path element and the raster image should always be scaled the same way meaning that any length in real world units such as 2,5 cm should correspond to the same amount of pixels in both the path and in the raster image. Correspondingly, I get the pixel per cm value for the path by taking it's pixel width and dividing it by it's width in cm (user space units / 10). For the raster image, I measure the width in pixels that one black square takes up and divide the amount by it's known real world width of 2,5 cm.
– Wulf
Nov 16 '18 at 9:45
1
Then I can't reproduce your numbers. For me, if I change the scale of the grafic on the screen, the position of the image never changes in relation to the path. What is shown in the upper left corner, remains in the upper left corner, same as for right and bottom. The distances between the three corners always represent the same real-world distances and are taken up always by the same amount of image content. Aspect ratio is preserved, so all measurements are scaled with the same factor. As far as I can see, that is exactly what you asked for.
– ccprog
Nov 16 '18 at 13:34
add a comment |
Make your life easier and do not try to first fit an image into a pattern, and then to fit that pattern repeatedly (at least conceptually) into a path, so that you have a total of three implicit size transformations to keep track of, when all you need is to size the image correctly.
If I understand you correctly, your userspace units should equal 1mm. Then, when
- 2.04 image pixel equals 1mm equals 1 userspace unit
- your image needs to be scaled by 1 / 2.04
- making your image scale from 1440 × 1080 to 706 × 529 (rounded, the
preserveAspectRatio
will take care of the rest)
Instead of fitting a "pattern" fill inside the path, you can also cut the path shape out of the image with a clip-path. - It is actually the same process as cutting a part out of a cloth, btw…
<svg id="svgView-1" style="width:90vw" viewBox="0 0 635 334" >
<clipPath id="clip">
<path d="M0 0 L635 0 L334 290 Z "></path>
</clipPath>
<image xlink:href="https://cdn.shopify.com/s/files/1/0081/1076/8185/products/3.jpg?v=1540031315"
x="0" y="0"
width="706" height="529"
preserveAspectRatio="xMidYMid slice"
clip-path="url(#clip)"/>
</svg>
Make your life easier and do not try to first fit an image into a pattern, and then to fit that pattern repeatedly (at least conceptually) into a path, so that you have a total of three implicit size transformations to keep track of, when all you need is to size the image correctly.
If I understand you correctly, your userspace units should equal 1mm. Then, when
- 2.04 image pixel equals 1mm equals 1 userspace unit
- your image needs to be scaled by 1 / 2.04
- making your image scale from 1440 × 1080 to 706 × 529 (rounded, the
preserveAspectRatio
will take care of the rest)
Instead of fitting a "pattern" fill inside the path, you can also cut the path shape out of the image with a clip-path. - It is actually the same process as cutting a part out of a cloth, btw…
<svg id="svgView-1" style="width:90vw" viewBox="0 0 635 334" >
<clipPath id="clip">
<path d="M0 0 L635 0 L334 290 Z "></path>
</clipPath>
<image xlink:href="https://cdn.shopify.com/s/files/1/0081/1076/8185/products/3.jpg?v=1540031315"
x="0" y="0"
width="706" height="529"
preserveAspectRatio="xMidYMid slice"
clip-path="url(#clip)"/>
</svg>
<svg id="svgView-1" style="width:90vw" viewBox="0 0 635 334" >
<clipPath id="clip">
<path d="M0 0 L635 0 L334 290 Z "></path>
</clipPath>
<image xlink:href="https://cdn.shopify.com/s/files/1/0081/1076/8185/products/3.jpg?v=1540031315"
x="0" y="0"
width="706" height="529"
preserveAspectRatio="xMidYMid slice"
clip-path="url(#clip)"/>
</svg>
<svg id="svgView-1" style="width:90vw" viewBox="0 0 635 334" >
<clipPath id="clip">
<path d="M0 0 L635 0 L334 290 Z "></path>
</clipPath>
<image xlink:href="https://cdn.shopify.com/s/files/1/0081/1076/8185/products/3.jpg?v=1540031315"
x="0" y="0"
width="706" height="529"
preserveAspectRatio="xMidYMid slice"
clip-path="url(#clip)"/>
</svg>
edited Nov 14 '18 at 20:25
answered Nov 14 '18 at 20:17
ccprogccprog
9,22621027
9,22621027
thank you for this answer. I like your idea of not doing so many size transformations. Unfortunately, I think your proposed solution doesn't quite work the way I need it to. When I open this in fullscreen, I get different pixel per cm values for the path (22.7) than for the fabric raster image (21.6). Scaling the svg together with the path element when the viewsize changes is, unfortunately, a hard requirement.
– Wulf
Nov 15 '18 at 8:17
The reason for using the path fill is that I want to display the empty path and then the user can select a fabric to fill it. A picture say more than a thousand words so I made a screenshot off the whole app sofar: imgur.com/a/3gTSZ9g
– Wulf
Nov 15 '18 at 8:19
1
Frankly, I don't understand your requirement. "Scaling the svg together with the path element" seemed to indicate: Whatever size the SVG is displayed at, each detail of the image should remain at the same place relative to the outline of the path. That is what happens. How do you compute those "pixel per cm" values?
– ccprog
Nov 15 '18 at 13:46
sorry, apparantly I misspoke, I mean the path element and the raster image should always be scaled the same way meaning that any length in real world units such as 2,5 cm should correspond to the same amount of pixels in both the path and in the raster image. Correspondingly, I get the pixel per cm value for the path by taking it's pixel width and dividing it by it's width in cm (user space units / 10). For the raster image, I measure the width in pixels that one black square takes up and divide the amount by it's known real world width of 2,5 cm.
– Wulf
Nov 16 '18 at 9:45
1
Then I can't reproduce your numbers. For me, if I change the scale of the grafic on the screen, the position of the image never changes in relation to the path. What is shown in the upper left corner, remains in the upper left corner, same as for right and bottom. The distances between the three corners always represent the same real-world distances and are taken up always by the same amount of image content. Aspect ratio is preserved, so all measurements are scaled with the same factor. As far as I can see, that is exactly what you asked for.
– ccprog
Nov 16 '18 at 13:34
add a comment |
thank you for this answer. I like your idea of not doing so many size transformations. Unfortunately, I think your proposed solution doesn't quite work the way I need it to. When I open this in fullscreen, I get different pixel per cm values for the path (22.7) than for the fabric raster image (21.6). Scaling the svg together with the path element when the viewsize changes is, unfortunately, a hard requirement.
– Wulf
Nov 15 '18 at 8:17
The reason for using the path fill is that I want to display the empty path and then the user can select a fabric to fill it. A picture say more than a thousand words so I made a screenshot off the whole app sofar: imgur.com/a/3gTSZ9g
– Wulf
Nov 15 '18 at 8:19
1
Frankly, I don't understand your requirement. "Scaling the svg together with the path element" seemed to indicate: Whatever size the SVG is displayed at, each detail of the image should remain at the same place relative to the outline of the path. That is what happens. How do you compute those "pixel per cm" values?
– ccprog
Nov 15 '18 at 13:46
sorry, apparantly I misspoke, I mean the path element and the raster image should always be scaled the same way meaning that any length in real world units such as 2,5 cm should correspond to the same amount of pixels in both the path and in the raster image. Correspondingly, I get the pixel per cm value for the path by taking it's pixel width and dividing it by it's width in cm (user space units / 10). For the raster image, I measure the width in pixels that one black square takes up and divide the amount by it's known real world width of 2,5 cm.
– Wulf
Nov 16 '18 at 9:45
1
Then I can't reproduce your numbers. For me, if I change the scale of the grafic on the screen, the position of the image never changes in relation to the path. What is shown in the upper left corner, remains in the upper left corner, same as for right and bottom. The distances between the three corners always represent the same real-world distances and are taken up always by the same amount of image content. Aspect ratio is preserved, so all measurements are scaled with the same factor. As far as I can see, that is exactly what you asked for.
– ccprog
Nov 16 '18 at 13:34
thank you for this answer. I like your idea of not doing so many size transformations. Unfortunately, I think your proposed solution doesn't quite work the way I need it to. When I open this in fullscreen, I get different pixel per cm values for the path (22.7) than for the fabric raster image (21.6). Scaling the svg together with the path element when the viewsize changes is, unfortunately, a hard requirement.
– Wulf
Nov 15 '18 at 8:17
thank you for this answer. I like your idea of not doing so many size transformations. Unfortunately, I think your proposed solution doesn't quite work the way I need it to. When I open this in fullscreen, I get different pixel per cm values for the path (22.7) than for the fabric raster image (21.6). Scaling the svg together with the path element when the viewsize changes is, unfortunately, a hard requirement.
– Wulf
Nov 15 '18 at 8:17
The reason for using the path fill is that I want to display the empty path and then the user can select a fabric to fill it. A picture say more than a thousand words so I made a screenshot off the whole app sofar: imgur.com/a/3gTSZ9g
– Wulf
Nov 15 '18 at 8:19
The reason for using the path fill is that I want to display the empty path and then the user can select a fabric to fill it. A picture say more than a thousand words so I made a screenshot off the whole app sofar: imgur.com/a/3gTSZ9g
– Wulf
Nov 15 '18 at 8:19
1
1
Frankly, I don't understand your requirement. "Scaling the svg together with the path element" seemed to indicate: Whatever size the SVG is displayed at, each detail of the image should remain at the same place relative to the outline of the path. That is what happens. How do you compute those "pixel per cm" values?
– ccprog
Nov 15 '18 at 13:46
Frankly, I don't understand your requirement. "Scaling the svg together with the path element" seemed to indicate: Whatever size the SVG is displayed at, each detail of the image should remain at the same place relative to the outline of the path. That is what happens. How do you compute those "pixel per cm" values?
– ccprog
Nov 15 '18 at 13:46
sorry, apparantly I misspoke, I mean the path element and the raster image should always be scaled the same way meaning that any length in real world units such as 2,5 cm should correspond to the same amount of pixels in both the path and in the raster image. Correspondingly, I get the pixel per cm value for the path by taking it's pixel width and dividing it by it's width in cm (user space units / 10). For the raster image, I measure the width in pixels that one black square takes up and divide the amount by it's known real world width of 2,5 cm.
– Wulf
Nov 16 '18 at 9:45
sorry, apparantly I misspoke, I mean the path element and the raster image should always be scaled the same way meaning that any length in real world units such as 2,5 cm should correspond to the same amount of pixels in both the path and in the raster image. Correspondingly, I get the pixel per cm value for the path by taking it's pixel width and dividing it by it's width in cm (user space units / 10). For the raster image, I measure the width in pixels that one black square takes up and divide the amount by it's known real world width of 2,5 cm.
– Wulf
Nov 16 '18 at 9:45
1
1
Then I can't reproduce your numbers. For me, if I change the scale of the grafic on the screen, the position of the image never changes in relation to the path. What is shown in the upper left corner, remains in the upper left corner, same as for right and bottom. The distances between the three corners always represent the same real-world distances and are taken up always by the same amount of image content. Aspect ratio is preserved, so all measurements are scaled with the same factor. As far as I can see, that is exactly what you asked for.
– ccprog
Nov 16 '18 at 13:34
Then I can't reproduce your numbers. For me, if I change the scale of the grafic on the screen, the position of the image never changes in relation to the path. What is shown in the upper left corner, remains in the upper left corner, same as for right and bottom. The distances between the three corners always represent the same real-world distances and are taken up always by the same amount of image content. Aspect ratio is preserved, so all measurements are scaled with the same factor. As far as I can see, that is exactly what you asked for.
– ccprog
Nov 16 '18 at 13:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302668%2fhow-can-i-scale-a-raster-image-to-user-space-units-in-svg%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The way you use the pattern, its content is never repeated (never shown more than once). Do you expect to use it in a way that repetitions could happen? Your example image would not be suitable for such a use.
– ccprog
Nov 14 '18 at 16:43
@ccprog thanks for your comment. the sample image is just that, a test image I can use to get this correct. For real usage, the images will be better all alround and won't contain the calibration pattern. I don't think I'll be using tiling, as it stands now each image is larger in real space then any of the paths would ever be(if that makes sense)
– Wulf
Nov 14 '18 at 18:32