Jump to content
John Rostron

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:

oChequer01.png.7fe756146113a9701e04c174bd5db243.png

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:

Chequer02.png.5725920e79ef89c008d1bbd47e1c9273.png

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:

Chequer03.png.ca875e0c46aa9f91db6e8b25ed304c8f.png

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.

Chequer04.png.5d40bc4919ba760a10d1f4410dabf733.png

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:

WrapAroundV2.afmacro

 

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 this post


Link to post
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 this post


Link to post
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.
 

wrap.mov

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.4 iPad Pro iPadOS

 

Continuous improvement is better than delayed perfection 

Share this post


Link to post
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 this post


Link to post
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.4 iPad Pro iPadOS

 

Continuous improvement is better than delayed perfection 

Share this post


Link to post
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 this post


Link to post
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  

curvewarpmacros.afmacros

*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 this post


Link to post
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:

Oswalds01.png.a257781592c566fb762fbd6f53e3603a.png

and after (with Crop Canvas):

Oswalds04.png.890989f8576ee850684b4b1bde4789f9.png

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 this post


Link to post
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.4 iPad Pro iPadOS

 

Continuous improvement is better than delayed perfection 

Share this post


Link to post
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 this post


Link to post
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) ?

I just downloaded this one WrapAround1.8.afmacro 976 B · 12 downloads   

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.4 iPad Pro iPadOS

 

Continuous improvement is better than delayed perfection 

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

S-curve CLIP.afmacros

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

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

Curve-warp CLIP.afmacros

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

rasterize - Horizontal Curvature Shift equation - clip canvas

 

 

Share this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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


×
×
  • Create New...

Important Information

Please note the Annual Company Closure section in the Terms of Use. These are the Terms of Use you will be asked to agree to if you join the forum. | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.