Canvas resize: How to set image margin to canvas in pixel/percent?

XnConvert Multi Platform - Windows, MacOSX, Linux

Moderators: helmut, XnTriq, xnview

H5T7P4
Posts: 17
Joined: Mon Apr 06, 2020 6:41 pm

Canvas resize: How to set image margin to canvas in pixel/percent?

Post by H5T7P4 »

Hello I have a svg file that I want to position on a canvas of 4500x5400 pixel with the most possible
width of the picture what is possible with keeping ratio what I have reached with the first two actions
(you can see it in the picture).

Finally I want to position my picture in the upper area of the canvas but NOT on the highest top position.

I want to have a margin to the top. But in the Canvas resize selection box it's only possible to choose
Top, Top right, Left and so on.

So is there a possibility to set a margin to the choosed position?:
For example I choose position Top and 50 pixel margin or choose Left and 10 percentage margin.

Here a picture what I have done (rectangle over image because I'm not the copyright holder):

Bild_2020_04_06_20_54_43_458_Retusche.jpg
You do not have the required permissions to view the files attached to this post.
cday
XnThusiast
Posts: 4349
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by cday »

Not too easy to understand, but in effect you wish to move the image up towards the top of the black area, but not all the way to the top?

If so, a workaround might be to use a Crop action to remove black canvas at the top to give the required margin, then a Canvas resize action with the anchor Position set to Top to add the same amount of black canvas at the bottom...

Does that make sense, or can you clarify further?

Note: Your image placed between Img tags didn't display as it linked to the webpage hosting the image rather than to the image, so I have downloaded the file and inserted it as an attachment.
H5T7P4
Posts: 17
Joined: Mon Apr 06, 2020 6:41 pm

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by H5T7P4 »

Thanks for inserting the file.

No I don't want to have the image in the black area.
I want to have it in the transparent area (the canvas).

But I want to have a margin to the top of my transparent area
and my image.
cday
XnThusiast
Posts: 4349
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by cday »

H5T7P4 wrote: Mon Apr 06, 2020 8:47 pm No I don't want to have the image in the black area.
I want to have it in the transparent area (the canvas).

But I want to have a margin to the top of my transparent area
and my image.
Right, the black area I referred to above is the background in your Preview window, I presume!

I'm not clear exactly what you are doing, are there other actions selected which aren't displayed in your screenshot?

In particular, are you using a Watermark action? If so, there is in fact an option to apply the watermark with an offset or 'Delta' relative the top (for eample) of the image, if you are able to obtain the result you need using that option?

Edit:

If it is any help, the watermark function can actually be regarded as a general 'paste' function: the 'watermark' file doesn't have to be transparent, and doesn't have to be small... Possibly you can modify your steps to exploit that?
H5T7P4
Posts: 17
Joined: Mon Apr 06, 2020 6:41 pm

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by H5T7P4 »

Perhaps it's important to know my input file is a svg File.
Then with the actions I want to place the image in the svg file it at the top
(but with a margin to the top) on a 4500x5400 pixel canvas.
And as output I want a png image.

I don't know hwo to handle with the Watermark action.
My input file is an svg and the Watermark action cannot handle svg.
So I don't think I can use it.

Is there a function to add transparent pixel to an image?
So I could add a transparent 50 pixel area at the top of
the image after the Automatic crop action and at the Canvas resize action
I would have autmatically a distance of 50 pixel to the top of the canvas
if I set position top?
cday
XnThusiast
Posts: 4349
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by cday »

At a quick look, I would suggest opening the SVG image in an image editor such as XnView (Classic or MP). and then saving it as a bitmap file, PNG for example, and theh applying (pasting) the resulting image onto your canvas using the Watermark action with the required Delta offset from the top of the canvas...
H5T7P4
Posts: 17
Joined: Mon Apr 06, 2020 6:41 pm

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by H5T7P4 »

The originally image was an eps file. But XnConvert couldn't handle it.
So I converted it to a svg file with Illustrator. Now XnConvert can handle it.

But the problem is that in the eps/svg file the vector is shown very small
with a big canvas around. So if I save it as it is as a png I would get a
very small image with a big canvas around it.

If I then use Automatic crop with XnConvert after that I would
get a very pixelated image.

And I want to do it with a lot of svg images. So want to do
it with a batch. I don't know if XnView can work with batches.

And I don't know if I can then work with the png in XnConvert
like with a svg.

Ok, so there seems to be to possibilities but more complicated.

The only batch I use now is one in Illustrator to convert my eps
to svg files and then XnConvert.

It would be great if there would be a function in XnConvert Canvas
resize action to move images within a canvas not only to top,
bottom and so forth but also in pixels or percent.
cday
XnThusiast
Posts: 4349
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by cday »

H5T7P4 wrote: Tue Apr 07, 2020 8:45 pm The originally image was an eps file. But XnConvert couldn't handle it.
It should be able to open it if you have Ghostcript installed...

But the problem is that in the eps/svg file the vector is shown very small with a big canvas around. So if I save it as it is as a png I would get a
very small image with a big canvas around it.
As EPS and SVG are vector formats, you should be able to get satisfactory images if you set a suitable DPI value at which to open them (for EPS, at least). You will need to find some relevant settings in the interface, though!

And I don't know if I can then work with the png in XnConvert
Shouldn't be a problem...

I don't know if XnView can work with batches.
XnView Classic, 'MP and even better XnConvert [recommended] support batch conversions.

It would be great if there would be a function in XnConvert Canvas resize action to move images within a canvas not only to top, bottom and so forth but also in pixels or percent.
I think the Watermark action is probably the only option.
H5T7P4
Posts: 17
Joined: Mon Apr 06, 2020 6:41 pm

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by H5T7P4 »

Yes, I find now a way to use the Watermark action and to do all in XnConvert,
but I have a problem with the Watermark action:

As step one I import my svg and do only the first two actions (Automatic crop and Resize
(Mode: Width, Width: 4500 pixels)). Then I convert to png.

At second step I import the 4500 pixel png (and height pixel ratio accordingly) that was created in step one.

Now I do only the Canvas resize (4500x5400 pixel) and the Watermark action.

But the last problem is, that the Watermark action doesn't work as I supposed:

In the Watermark action I set Position: Top and then to move away a little bit
from the top a delta of 800 for Y.

But instead of only moving my picture a little bit down I get a second picture.
You can see it in the second picture.

So why I get a second picture instead of only a moved down picture?
And how can I prevent to get a second picture?

First I do this with my svg file and convert it to a png file:

646add-1586304179.png


Then I import the png file I made in step one and do this two steps:

7e773e-1586304278.png
You do not have the required permissions to view the files attached to this post.
cday
XnThusiast
Posts: 4349
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by cday »

Your images between Img tags didn't display again, and I couldn't easily see how to edit them so that they were directly visible in your post.

Would you please post any further images as attachments, referring to this tutorial if necessary.

I need to look more closely at your post later as I am still finding it hard to follow.

Are the light grey areas in the screenshots parts of the image that you are obscuring because you don't want them to be visible, or do the images show what you actually see yourself on the screen?

And if the early steps are working correctly, can you reduce the problem to the final watermark step which is not producing the result you need, and ideally provide test images that can be used to illustrate the problem, not necessarily the files that you are using now?
H5T7P4
Posts: 17
Joined: Mon Apr 06, 2020 6:41 pm

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by H5T7P4 »

Yes, grey areas were to obscure because I'm not the copyright holder of the image.
But I can show it with another example without obscuring:
In Illustrator I created an svg with an ellipse image.

As step one I imported it in XnConvert and have done the Automatic crop and Resize action and converted to a png file:
1_Ellipse.jpg
As new input I took the png from step one and done the Canvas and the Watermark filter:
2_Ellipse.jpg
I set a delta of 1000 for Y to move the image down from the top,
but I then get two images instead of one a little bit down from the top.

Ok, I think now I understand why this happens. Because the Watermark is a second image.
And only the watermark image can be moved around.

Or it would be great if there were a Delta setting also for the Canvas resize action in one of
the next versions of XnConvert.

So this should work:

Generate a full transparent image without an image in it with the dimensions
I want and use this as the input file for XnConvert.

Then in the Watermark action I import the image I created in the first step.
Now I can move it away from the top by setting a Delta for Y.
Then I click convert and have what I want.

But now I see the next problem:

Automation only works for the images I have added in the Input tab.
But there I only need one transparent image and I would need to
do the Watermark action for all files of an folder but there I can only
set one Image filename.

So if I want to do this for 100 files I have to set Image filename in the Watermark action
100 times manually.

Is there a solution to automate this?

Or it would be great if there were also a Delta setting for the Canvas resize action in
one of the next versions of XnConvert.
You do not have the required permissions to view the files attached to this post.
cday
XnThusiast
Posts: 4349
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by cday »

H5T7P4 wrote: Wed Apr 08, 2020 4:41 pm Yes, grey areas were to obscure because I'm not the copyright holder of the image.
You did say that originally, but I had forgotten with all the later details...

If I follow correctly, without spending too much time reading you post in every detail, the double image was due to your 'watermarking' with a delta an image that already had the same image on it, still thinking no doubt about your earlier idea to move that image on the original canvas?

If you wish to apply the same 'watermark' to all your images that shouldn't be a problem, but if the 'watermark' changes for each image you would have to run XnConvert separately for each 'watermark'. However, if you are familiar with scripting at the command line, you could probably use the command line utility NConvert with some additional code to step through the 'watermark' images as required. Reasonable experience with coding at the command line required, though.

I'm not entirely clear what you require in your reference to filenames, though, if you wish to elaborate on that, possibly there is a solution.

If you wish to request the addition of a delta offset in the Canvas resize action you could make a request in an new thread, but I'm not sure whether that would be practical or whether there would be general interest in it??

So your original problem now essentially solved?
H5T7P4
Posts: 17
Joined: Mon Apr 06, 2020 6:41 pm

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by H5T7P4 »

The Watermark action image filename has to change for every image, because it seems to be the only action way to move images
around and I want to move all my images to get a margin to the top.

So to do it as a batch I have to learn NConvert if I interpret your answer right.
So your original problem now essentially solved?
Yes, if I have only a few files. But if I have a lot of files I need to learn
how to use NConvert to do it as a batch.
cday
XnThusiast
Posts: 4349
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by cday »

H5T7P4 wrote: Wed Apr 08, 2020 8:43 pm The Watermark action image filename has to change for every image, because it seems to be the only action way to move images
around and I want to move all my images to get a margin to the top.
I'm not entirely sure that I understand: if there is actually a way to do what you need using XnConvert, that is certainly the best solution.

So to do it as a batch I have to learn NConvert if I interpret your answer right.

... if I have a lot of files I need to learn how to use NConvert to do it as a batch.
Unless you have previous command line experience don't underestimate what that will involve: working at the command line can be very unforgiving at first, you will need to learn a little but not too much NConvert code, and you will need to learn how to add some general cmd.exe (modern, enhanced 'DOS') code to use variables that are incremented and to loop through the files to be processed.

That is assuming that what you need to do is possible, which it probably is, remembering that my own quite limited experience was not gained easily and I wouldn't be able to offer much if any support due to the time that would be required with my limited knowledge... I don't want to discourage you but make sure that there isn't an XnConvert solution first! :wink:
cday
XnThusiast
Posts: 4349
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Canvas resize: How to set image margin to canvas in pixel/percent?

Post by cday »

I have been thinking about your overall problem from various points of view, but before any further detailed consideration of possible XnConvert or NConvert solutions, it would be necessary to clearly define the relevant parts of the overall problem.

Meanwhile I have a simple test for you to try:

1_Ellipse.jpg

In the above image from your 18:41 post above, you have a file representing one of your one hundred SVG images placed on a transparent canvas, and you haven't yet used the watermark action?

And you need to enlarge the transparent canvas, and on the resulting canvas position the blue ellipse slightly below the top of the image?

The test: Could you set up a 'Canvas resize' to increase the height of the image with the 'Position' (anchor) set to ''Center' and see the resulting preview -- because a 'Background' colour will set, and there is no 'Transparent' option, I am not sure what the result will be... :?:

Could you post a screenshot, please.
You do not have the required permissions to view the files attached to this post.