# Macro to wrap an Image around a Bottle or Mug - revisited

## Recommended Posts

Posted (edited)

Some time ago I produced a macro to Wrap an Image around a Bottle or Mug. This involved some complex trigonometrical operations on the image. I present here an alternative approach for a macro to perform the same action.

Here is my original image:

o

It is easily possible to produce an equation that contracts the image width-wise to emulate the reduction in perceived width as the image is wrapped. Such an equation has the form:

x=w/2+(w/2-x)*pi/2

and has the result of:

The contraction is uniform across the reduced width. The expression pi/2 is the appropriate scaling for a bottle diameter that accepts the image around its half-circumference.

What I was aiming for was a function that would scale the edges so that they appeared contracted, whilst applying zero scaling to the centre of the image. After much trial and error, I came up with this:

x=w/2-(w/2-x)*(1+1.571*(1-sqrt(1-(1-2*x/w)^2)))

Edit: Note that this has a minus sign after the first w/2. The original had a plus sign.

The value 1.571 is just half pi. The resulting image is:

This is a single result. I have further refined by including a scaling parameter, a, which accentuates the compression at the edges.

w/2+(w/2-x)*(1+(1.571/a)*(1-sqrt(1-(1-2*x/w)^2)))

Here it is with the a parameter around half.

Note that in these images, the central squares remain square.

Edit: Like my previous version it has a parameter (in this case b) which affects the viewpoint, above or below. If you want to use this then you need to enlarge the canvas vertically beforehand to give room for the curvature. You may wish to use Document > Clip Canvas at the end in this case.

Edit: various members had pointed out that the final image was flipped horizontally. This has now been fixed. I have also added Layer > Unlock and Layer > Rasterize at the start of the macro. I have not added a clip canvas at the end. Do you think that this is desirable?

Here is the macro:

John

Edited by John Rostron
Update

Windows 10, Affinity Photo 1.8,3 Designer 1.8.3 and Publisher 1.8.3 (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

##### Share on other sites

John,

I've played your macro - brilliant.
Resetting now goes without a hitch.
However, besides wrapping, it also flips the picture horizontally.
It makes no difference whether I copy & paste the function directly, or play the macro,
change the extend mode to randomly. It always flips the picture.
You would not have been able to notice this happening, when creating & testing the macro because of the checkerboard example.
This will remain a checkerboard whatever the macro will perform and flipping (no pun intended !) would not be noticed.
Here's a screenrecording to show what I mean.
(Just one extend mode used, no changes made to parameters).
In the meantime, thanks again for your effort.
Best, C.L.

That what you do not yet know is more important than what you already know-Jordan Peterson

##### Share on other sites
1 hour ago, catlover said:

John,

I've played your macro - brilliant.
Resetting now goes without a hitch.
However, besides wrapping, it also flips the picture horizontally.
It makes no difference whether I copy & paste the function directly, or play the macro,
change the extend mode to randomly. It always flips the picture.
You would not have been able to notice this happening, when creating & testing the macro because of the checkerboard example.
This will remain a checkerboard whatever the macro will perform and flipping (no pun intended !) would not be noticed.
Here's a screenrecording to show what I mean.
(Just one extend mode used, no changes made to parameters).
In the meantime, thanks again for your effort.
Best, C.L.

catlover,  ran into same problem on vertical oriented photos.  Horiz no problems...John fixed this problem in last macro with rasterize.  I have tested this and it works no problem, just rasterize and it should work for you too!  PS. John,  while it is good form to add unlock as a macro step, rasterize seems to unlock the images without that step.  So far, I have only run into this issue with distortion related commands on Vertical oriented images.  Keep up the good work!  - T V    Update...this is flipping the image horizontally for me.  Without rasterize, it flips horizontally and vertically.

##### Share on other sites

The images were rasterized in my example, so what else could cause this to happen ?

That what you do not yet know is more important than what you already know-Jordan Peterson

##### Share on other sites

The equation is interesting to play with...and manipulating it does some fun mirroring and warping.  I am missing the y calculation with second parameter...flip document?

##### Share on other sites

When I try to import the Macro in Library from Desktop, the file is grayed out. If I drag and drop into open Photo document  I get "This file is not Affinity document."  What am I'm doing wrong, please. Thank you.

Cecil

iMac Retina 5K, 27”, 2019. 3.6 GHz Intel Core 9, 40 GB Memory DDR4, Radeon Pro 580X 8 GB, macOS 10.5.6, iPad Pro iPadOS

Continuous improvement is better than delayed perfection

##### Share on other sites

The macro cannot be imported into the Library, you have to load it via View>Studio>Macro>import ( the little square with the down-arrow.).

That what you do not yet know is more important than what you already know-Jordan Peterson

##### Share on other sites
11 minutes ago, catlover said:

The macro cannot be imported into the Library, you have to load it via View>Studio>Macro>import ( the little square with the down-arrow.).

The first time I did that for some reason Import would not open, however it did work this go around and I saved to the Library. Thank you.

Cecil

iMac Retina 5K, 27”, 2019. 3.6 GHz Intel Core 9, 40 GB Memory DDR4, Radeon Pro 580X 8 GB, macOS 10.5.6, iPad Pro iPadOS

Continuous improvement is better than delayed perfection

##### Share on other sites

@catlover, @T V, @Cecil, Thanks to all for your feedback. I was unaware of the flipping problem. I usually start off my macros with unlock and rasterise, but I did not in this case. I will amend the macro and re-post. I will also edit the original posting.

Like my previous version it has a parameter (in this case b) which affects the viewpoint, above or below. If you want to use this then you need to enlarge the canvas vertically beforehand to give room for the curvature.

John

Windows 10, Affinity Photo 1.8,3 Designer 1.8.3 and Publisher 1.8.3 (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

##### Share on other sites

John, here is something to consider...including your macro(renamed 'equation').  Run either...hope this helps, feel free to rewrite...I have done this to all of them and I get a better feel for what you are doing.  Really great stuff - T V

*one further macro option is to merge visible to start...that way you unlock and select that new layer from a position of having a layer selected or not when you run the macro.

##### Share on other sites

I have amended the macro to take onboard the comments  from  @catlover, @T V, and @Cecil,  I have given the amendments in some edits in the original posting. Here is an example of the revised macro. It is of a stained glass window in St Oswald's church, Oswestry, Shropshire.

Before:

and after (with Crop Canvas):

John

Windows 10, Affinity Photo 1.8,3 Designer 1.8.3 and Publisher 1.8.3 (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

##### Share on other sites

@John Rostron very nice. Is this just modifying the original download or will you post updated macro? Thank you, your work is outstanding.

Cecil

iMac Retina 5K, 27”, 2019. 3.6 GHz Intel Core 9, 40 GB Memory DDR4, Radeon Pro 580X 8 GB, macOS 10.5.6, iPad Pro iPadOS

Continuous improvement is better than delayed perfection

##### Share on other sites
Just now, Cecil said:

will you post updated macro?

The original posting now has a link to the updated macro.

I shall provide a couple of extra macros as follows:

One to Merge visible first (as @T V has suggested).

One with this plus a Document > Clip Canvas at the end.

I feel that there are circumstances where the plain macro without these addition would be appropriate.

John

Windows 10, Affinity Photo 1.8,3 Designer 1.8.3 and Publisher 1.8.3 (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

##### Share on other sites

Thanks, John.

Going to have a go ASAP and let you know my findings.

The original macro : is that this one (below) ?

That what you do not yet know is more important than what you already know-Jordan Peterson

##### Share on other sites
50 minutes ago, catlover said:

Thanks, John.

Going to have a go ASAP and let you know my findings.

The original macro : is that this one (below) ?

It’s V2, located at end of first post.

Cecil

iMac Retina 5K, 27”, 2019. 3.6 GHz Intel Core 9, 40 GB Memory DDR4, Radeon Pro 580X 8 GB, macOS 10.5.6, iPad Pro iPadOS

Continuous improvement is better than delayed perfection

##### Share on other sites

Thanks, Cecil. Found it.

That what you do not yet know is more important than what you already know-Jordan Peterson

##### Share on other sites

John, looks good.  Personally, I prefer to see the edges.  Clipping the canvas would be good for saving file size.  Are you starting a 'Heavenly Brew'?  Cheers - T V

##### Share on other sites

Clipping Macros

I haven't been making macros everyday lately, so, I thought I would try some new things to get confidence with these equation anomalies...tested on horiz & vert format images and working great.  - notes : larger canvas - 10,000 px  x 10,000 px , clip canvas crops to image size leaving curved edges exposed , controls modified in equation...    👽 - T V

larger canvas - rasterize - S-curve equation - clip canvas

larger canvas - rasterize - S-curve Radial equation - clip canvas

larger canvas - rasterize - Curve-warp equation - clip canvas

rasterize - Horizontal Curvature Shift equation - clip canvas

##### Share on other sites
On 5/20/2020 at 10:25 AM, John Rostron said:

I shall provide a couple of extra macros as follows:

One to Merge visible first (as @T V has suggested).

One with this plus a Document > Clip Canvas at the end.

I have decided against providing these additional macros.

Adding Merge Visible at the beginning creates a suitable target layer on top of the stack, but the original layers are still visible below, which somewhat defeats the purpose.

Adding Clip Canvas at the end of the macro does not work. It does indeed clip the canvas, but it does so before I have a chance to  adjust the parameters. I will explore this further and make a bug report if I feel that it needs it.

John

Windows 10, Affinity Photo 1.8,3 Designer 1.8.3 and Publisher 1.8.3 (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

##### Share on other sites
5 hours ago, John Rostron said:

I have decided against providing these additional macros.

Adding Merge Visible at the beginning creates a suitable target layer on top of the stack, but the original layers are still visible below, which somewhat defeats the purpose.

Adding Clip Canvas at the end of the macro does not work. It does indeed clip the canvas, but it does so before I have a chance to  adjust the parameters. I will explore this further and make a bug report if I feel that it needs it.

John

John,  Dido on the Merge VisibleClip Canvas worked like a live layer for me, but,  I do have to wait for the processing to catch up between changing settings as it is not instant.  Creating a larger canvas also seems to add to the bog at the beginning.  This is why I kept it lean and avoided the Merge.  It is completely possible to turn off visibility of layers in macros, but, how many and which ones...  - T V

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

×

• #### Affinity

×
• Create New...