Jump to content
You must now use your email address to sign in [click for more info] ×

Wrapping a label round a bottle or mug in Photo


Recommended Posts

In a recent post in Questions, @Maxxxworld asked how he could warp an image to apparently wrap it around a bottle. I posted a solution to his problem there, which I expand upon here.

Consider the facing semicircle of the bottle as seen in this diagram:

BottleLabel.png.1d2894599db84a705c9b938417def987.png

The visible part of the label extends from -90 degrees (on the left, not shown) to 90 degrees on the right. This will correspond to the width of the original image. This will project onto the final width of the image (the line below). The final width is less than the original width by a factor of pi/2. A bit of trigonometry shows that the sine of the Angle indicated is given by (x-halfwidth)/halfwidth, where halfwidth is both the label and the final image.

Putting this together and re-arranging a bit gives us an Equation:

x=(asin(2*x/w-1)*w/180)*pi/2+w/2

A bottle is typically viewed from above, so that the label has a curve, typically with a dip in the middle.This can easily be simulated using equations, using:

y=y-Const*x*(w-x)/w/w

The Constant determines the depth and direction of the curve. I have used the expression w*(0.5-a) as a scaling factor, where a is a parameter chosen at runtime. This will change the curve from negative (curving down) at the default a=1 to positive at a=0. Inserting this into the equation gives:

y=y+(0.5-a)*x*(w-x)/w

Note that the w in the numerator and denominator cancel out. The value of (0.5-a) determines the curvature as described above.

As an example, here is the Great West Window of Chester Cathedral. I chose this because it has lots of verticals to see how the filter affects it. (It has verticals once I had put it through the Mesh Warp.)

GreatWestWindow08.thumb.png.8607fc085b696a8181d42a2e2b08c48c.png

And here is the image after the filter:

GreatWestWindowWrap.thumb.png.051d85fa4411f6e55bcb7f596fd7ba54.png

Before filtering I cropped it close to the sides of the window and then Rasterized it to remove the invisible sides. I then added space at the top and bottom to allow room for the curvature part to operate. I then followed this by Clip Canvas to remove surplus transparent ends.

The calculations for this filter are complicated by the algorithm that Affinity uses to effect these equations, which I explain in this Tutorial here. I have created a macro that effects the filter, and then uses Clip Canvas. By clicking on the cogwheel, you can alter the degree and direction of curvature.

EDIT: I have discovered that this macro will only perform once (per Affinity Photo session). I add here a version recorded in version 1.8 which does work properly in Photo 1.8:

WrapAround1.8.afmacro  

I alos onclude here the original macro, recorded in version 1.7:

WrapAround.afmacro

John

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

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

Link to comment
Share on other sites

10 hours ago, dmstraker said:

Such lovely sums!

Gouraud shading next?

I had to look up what Gouraud shading was. I may be good at these lovely sums, but Gouraud shading looks as if it would require me learning how to create and use gradients. Gradients are a technique that I have read about but have yet to use in earnest. So, I think that I will leave Gouraud shading off my bucket list for now.

John

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

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

Link to comment
Share on other sites

  • 2 months later...

Hi John,

 

Thanks so much for sharing these equations. Having trawled the web while looking for ways to 'apply' labels to pack shots of bottles in Affinity Photo, this tutorial (and the accompanying equations and macros) are about the only things I've found to achieve this result - and they do it so well!

 

I've been trying to work out how to change the amount of compression (which gives the effect of a 'fall off') on the sides of the 'label'. I understand that changing the variable mentioned (between 0 and 1) gives the effect of looking down/up at the 'label', but I'm wondering if there's a way to change the equation to give the appearance of the 'label' being wrapped around a larger object. Essentially it's a matter of persective, and I'm trying the make the left and right sides of the label compress more (in a smooth fashion), so that I can can achieve a effect of the label falling off as it curves around a round bottle, but with the camera as though it was square on to the bottle. My requirement is that as you get a wider label (that wraps further around the object), the compression applied the label will need to become more extreme as it reaches the 'edge' of the bottle.

 

I hope this makes some kind of sense!

 

Is there something I'm missing, or could you kindly point me in the direction of what I'd need to change in your equations?

 

Many thanks, 

Pete

Link to comment
Share on other sites

@PeteAxford, what you are looking for seems to be  mapping a label that is less than the half-circumference of the bottle or can. This should be possible and I will look into it. 

As a fudge, you could resize the canvas (not the document) so that the new width corresponded to the half-diameter. After transforming, you could then remove the excess background (make it transparent and then Clip Canvas)

John

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

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

Link to comment
Share on other sites

Hi John,

 

Thanks for such a prompt reply - I've been having a little play with the canvas sizes to see what effect it has, but can't get the extreme perspective shift I'm after.

 

The effect I'm trying to achieve is that of a label which is almost (or even) 100% of  the half-circumference of the bottle, so that the far left and right ends of the label end (or get towards ending) in a compressed mass of ink (as it would appear to camera).

 

Here's a little gif of what I'm thinking about... it's set to 0.5 to give the effect of shooting straight on to the bottle (rather than creating the up or down curve), but I can't get those edges to compress enough to give the sense of the label wrapping around the edges. It's .gif which flips between the before and after - as you can see, there's not much fall off (see the vertical bars) as it is (though there does seem to be more if I get the label to wrap up or down?).

 

Hope this helps clarify?!

 

Thanks again, 
Pete

 

 

May-15-2018 13-17-40.gif

Link to comment
Share on other sites

x+(150*a)*sin(360*x/w)

If I understand you correctly the above equation is a good place to start for what you want to achieve.  It should effectively reduce the spacing between the characters on the left and right side of the text frame to simulate a label on a curved bottle.

1. Centre the text frame horizontally in your document (Important)

2. Add the equation and adjust Slider A

(text will become wider and the effect may look a little strange at times)

3. After you apply the equation, reduce text frame width to desired width which should help the text look more natural

You will need to experiment with different values for slider A for different text frame sizes

I have no interest in placing labels on bottles but if you (or anyone) can improve on the above please post back with the steps / results

 

bottles.jpg

To save time I am currently using an automated AI to reply to some posts on this forum. If any of "my" posts are wrong or appear to be total b*ll*cks they are the ones generated by the AI. If correct they were probably mine. I apologise for any mistakes made by my AI - I'm sure it will improve with time.

Link to comment
Share on other sites

3 hours ago, carl123 said:

x+(150*a)*sin(360*x/w)

If I understand you correctly the above equation is a good place to start for what you want to achieve.  It should effectively reduce the spacing between the characters on the left and right side of the text frame to simulate a label on a curved bottle.

1. Centre the text frame horizontally in your document (Important)

2. Add the equation and adjust Slider A

(text will become wider and the effect may look a little strange at times)

3. After you apply the equation, reduce text frame width to desired width which should help the text look more natural

You will need to experiment with different values for slider A for different text frame sizes

This equation certainly has the desired effect of compressing the marginal parts of the image. It is an empirical solution (that is one that works) but it does not strictly conform to the geometry as shown in my original diagram at the start of this thread. My formula does conform to the geometry, but fails in that it does not perform the appropriate marginal compression.

Back, as they say, to the drawing board.

John

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

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

Link to comment
Share on other sites

Hello Gentlemen, 

Thank you both some much for your input and help on this matter.

 

@carl123 I've plugged in your maths and it's doing the job for me wonderfully. I've combined your 'x' section John's 'y' to create both the more extreme compression in the edges and the gentle curvature of the label. 

 

@John Rostron Your response did make me chuckle - I love your turns of phrase and they cheered up my morning no end! I'm not whizz on the fine art of geometry (can I call it an art?!), but I think I follow your point about appropriate marginal compression. 

 

I will of course be following this thread, so if you want to keep on experimenting then I will be keen to see where you arrive at.

 

Many thanks again; I wish you both a great day,

All the best, 

Pete

Link to comment
Share on other sites

  • 4 weeks later...

I would like to use this macro, however I have downloaded it into a folder named macros, when I try to import (via the AP studio library import )this macro the program does not see it within the folder.  Any help on importing this would be helpful. Cheers John

AMD Ryzen 7 5800 X. Nvidia GeForce RTX3060 64Gb Ram
Affinity Designer/Photo/Publisher 2.4 for Windows • Windows 11 (23H2 build 22631 3447) Home
Affinity Designer/Photo/Publisher 2.4 for iPad Pro 10.5  • iPad OS 17.3.1

Link to comment
Share on other sites

  • Staff

Hi pioneer,
.afmacro files (without the S at the end of macro) are the steps of a single macro and must be imported from the Macro panel clicking the last icon on the top right of the panel. 

.afmacros (with a S at the end) is a set of macros which are imported through the Library panel.

Link to comment
Share on other sites

Wow. that was a speedy response and a great answer.  I had tried this but the icon was greyed out.  Have now discovered you have to have an image loaded for this button to be visible. thanks once again John.

AMD Ryzen 7 5800 X. Nvidia GeForce RTX3060 64Gb Ram
Affinity Designer/Photo/Publisher 2.4 for Windows • Windows 11 (23H2 build 22631 3447) Home
Affinity Designer/Photo/Publisher 2.4 for iPad Pro 10.5  • iPad OS 17.3.1

Link to comment
Share on other sites

  • 7 months later...
On 3/4/2018 at 11:32 AM, John Rostron said:

x=(asin(2*x/w-1)*w/180)*pi/2+w/2

A bottle is typically viewed from above, so that the label has a curve, typically with a dip in the middle.This can easily be simulated using equations, using:

y=y-Const*x*(w-x)/w/w

Looks great but...

When I put either of these into the Distortion > Equation, do nothing. The text of the equation turns red though.

Does anyone know what I'm doing wrong, thanks

Link to comment
Share on other sites

The text will turn red if there is an error and it cannot parse the expression (usually a typo). Have you tried downloading and running the macro given near the beginning of the thread?

John

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

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

Link to comment
Share on other sites

  • 1 year later...
On 3/5/2018 at 12:32 AM, John Rostron said:

Consider the facing semicircle of the bottle as seen in this diagram:

BottleLabel.png.1d2894599db84a705c9b938417def987.png

The visible part of the label extends from -90 degrees (on the left, not shown) to 90 degrees on the right. This will correspond to the width of the original image. This will project onto the final width of the image (the line below). The final width is less than the original width by a factor of pi/2. A bit of trigonometry shows that the sine of the Angle indicated is given by (x-halfwidth)/halfwidth, where halfwidth is both the label and the final image.

Putting this together and re-arranging a bit gives us an Equation:

x=(asin(2*x/w-1)*w/180)*pi/2+w/2

@John Rostron John I am truely in awe of your math!

I have a similar yet inverse problem, I’ve shot 360 photos but want remove the vertical distortion from the equirectangular format.
Which looks like an image is rolled over a tube vertically.
A friend showed me a photoshop plug in that can do this, and it looks great to make an equirectangular photo look like a panaorama (with top and bottom cut off).
But I thought the equation editor in Affinity must be able to do this....

i have tried to reverse your equation.... but I am a math loser😰
Can I beg your help to figure out how to adjust images as I’m suggesting (sorry I’m new to these forums too so not yet too good on how to quote and add images).

The Origonal unaltered 360 images are 6080 x 3040.

E11DE39B-789C-4007-BD57-1299A7737213.jpeg

8A0D5611-F7B4-4461-9F7D-7ACD7EC284BC.jpeg

08CF2067-617F-4A07-9B65-C360C34E3364.jpeg

Edited by MaximusNZ
Link to comment
Share on other sites

@MaximusNZ, as far as I can tell, you are seeking an equation that will expand the image vertically more at the top and bottom than in the middle. There is no pre-determined geometry that you or I could follow, so an empirical solution would be in order (that is one that just looks right). Let me have a think about it and do a trial and I will get back to you.

John

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

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

Link to comment
Share on other sites

@MaximusNZ. Try this macro. It applies a simple sine curve and expands to top and bottom, whilst squeezing the centre.

I have uploaded both the single Macro and a Macro library containing this one macro. 

Expand Top and Bottom.afmacro

Expand Top and Bottom.afmacros

If you find that it is stretching/squeezing too much, let me know and I will see if I can add a parameter to reduce the effect.

John

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

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

Link to comment
Share on other sites

8 hours ago, John Rostron said:

If you find that it is stretching/squeezing too much, let me know and I will see if I can add a parameter to reduce the effect.

 

@John Rostron That’s looking amazing!

At first I found it was not quite right, then I realised I need to resize the canvas before applying the macro.
Then squeeze it a bit to look nicer.
And in the end I’ve ended up with a set of actions to make it look good:

Resize Canvas - Centered - Y axis to 6040 px
Run “ Expand Top and Bottom” Macro
Transform - Y scale 92% Y offset 506 px
Transform - Y scale 91% Y offset 45.7 px
Crop to look better top and Bottom

What I end up with is almost the same.
The top and bottom could do with a bit more stretch, but the middle bit the same.... yeah sounds hard.
I’ve created side by sides of my final result from the steps above versus the PS workflow.

BTW what is the equation you ended up using? Is there a way to use the “a” slider to adjust the outer stretch?
And do you have a Patron / way to buy you a coffee? (I live in New Zealand, where are you?)

 

5DDD535A-E23D-4E97-95B2-33E9DC675898.jpeg

B5FF3FA2-D5E0-467E-A923-E7D8C00731C3.jpeg

Link to comment
Share on other sites

On 4/30/2020 at 11:38 PM, MaximusNZ said:

And do you have a Patron / way to buy you a coffee? (I live in New Zealand, where are you?

I am a retired biology lecturer living in Essex, UK. I do this sort of thing for pleasure.  We will be enjoying a glass of Oyster Bay Sauvignon Blanc with Sunday lunch and think about New Zealand.

John

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

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

Link to comment
Share on other sites

  • 2 weeks later...

@catloverhad discovered that my original macro (recorded in Photo v1.7) will only perform once when using with v1.8. I have recorded that same macro in Photo v1.8 which is included here, as well as in the original posting. It now seems to work as expected.

WrapAround1.8.afmacro

John

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

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

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

Loading...
×
×
  • Create New...

Important Information

Terms of Use | 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.