Jump to content

Recommended Posts

I have been trying various ways of resizing a document that will work as a macro. My aim is to resize a document so that the longest side is some fixed length. I have devised a formula/equation that works in the Transform panel. However it will not operate as a macro. The formula will not work in Document > Resize either. I understand equation will work in Filter > Distort > Equations but I have not yet worked out how to get t to do what I want.

My first attempt to resize to a maximum side length of 800px with the shorter side of 600px is:

X = x*x/800/a

Y = y*y/600/a

I then used Document > Clip Canvas to remove the transparent area. This looked OK, but the size was about twice as large as it should be, 1737 ×1296 for a landscape and 1342×1789 for a portrait. I included the a parameter to allow me to resize, but there is no way I can read or impose a numerical value for a.

The logic of my formula is that x/800 and y/600 are the scaling factors between the target and actual sizes. The equations seem to require that I put these in reciprocally!

I can usually wrestle with these algebraic conundrums, but this seems to have me beat.


Windows 10, Affinity Photo 1.7 and Designer 1.7, (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

I'm curious why you don't use the "min" approach you discussed the other day. Did you find some problem with that, other than the Transform Panel showing the wrong size.


-- Walt

Windows 10 Home, version 1903 (18362.239), 16GB memory, Intel Core i7-6700K @ 4.00Gz, GeForce GTX 970
Affinity Photo 1.7.2.471 and 1.7.2.464 Beta   / Affinity Designer 1.7.2.471 and 1.7.2.4464 Beta  / Affinity Publisher 1.7.2.471 and 1.7.2.458 Beta

Share this post


Link to post
Share on other sites

I am aiming to use the min approach, once I have sussed out how to persuade Distort > Equations to get in the right ballpark for size! The Transform panel gives the right scaling OK, but it will not work in macros. You just get the dimensions as the  initial values  calculated by the macro


Windows 10, Affinity Photo 1.7 and Designer 1.7, (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

Please John, as soon as you have a working solution, be so friendly and make a step-by-step guide for resizing lot of docs. Thank you!

The theory-discussion here, is too much abstract for me. (i´m relative new to AP / GFX in general).

 

 


OSX 10.13.5  / iMac Retina 27" / AMD Radeon R9 M380 / Metall: on!

Share this post


Link to post
Share on other sites
4 hours ago, John Rostron said:

The logic of my formula is that x/800 and y/600 are the scaling factors between the target and actual sizes.

Would not the scaling factors be w/800 & h/600 for use in Filter > Distort > Equations, assuming the desired dimensions are 800 x 600? Setting X = x*w/800 & y = y*h/600 in the equations always seems to produce those dimensions for me. Adding an a, b, or c parameter is tricky because they range from 0 to 1, so anything that divides by a parameter would allow division by zero, which is I think why that makes the equation turn red, even when it works for >0 values.


Affinity Photo 1.7.2, Affinity Designer 1.7.2, Affinity Publisher 1.7.2; macOS High Sierra 10.13.6 iMac (27-inch, Late 2012); 2.9GHz i5 CPU; NVIDIA GeForce GTX 660M; 8GB RAM
Affinity Photo 1.7.2.153 & Affinity Designer 1.7.2.6 for iPad; 6th Generation iPad 32 GB; Apple Pencil; iOS 12.3.1

Share this post


Link to post
Share on other sites

The limited documentation on Distort that I can find makes no mention of w and h, which, by analogy with Transform, I would have thought logical to use. I will give it a go. That's what weekends are for!


Windows 10, Affinity Photo 1.7 and Designer 1.7, (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
1 minute ago, John Rostron said:

The limited documentation on Distort that I can find makes no mention of w and h, which, by analogy with Transform, I would have thought logical to use. I will give it a go. That's what weekends are for!

w & h do seem to work, but of course the x & y equations I mentioned force any image to 800 x 600 dimensions, which distorts ones that are taller than they are wide.


Affinity Photo 1.7.2, Affinity Designer 1.7.2, Affinity Publisher 1.7.2; macOS High Sierra 10.13.6 iMac (27-inch, Late 2012); 2.9GHz i5 CPU; NVIDIA GeForce GTX 660M; 8GB RAM
Affinity Photo 1.7.2.153 & Affinity Designer 1.7.2.6 for iPad; 6th Generation iPad 32 GB; Apple Pencil; iOS 12.3.1

Share this post


Link to post
Share on other sites
12 hours ago, R C-R said:

w & h do seem to work, but of course the x & y equations I mentioned force any image to 800 x 600 dimensions, which distorts ones that are taller than they are wide.

They do indeed, and I can now scale any image to a specified target. Now I shall be attempting to create an equation that will scale to a fixed maximum dimension, interspersed with preparing Sunday lunch. I shall be using Excel to investigate suitable equations before trying them in Affinity.


Windows 10, Affinity Photo 1.7 and Designer 1.7, (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
11 minutes ago, John Rostron said:

They do indeed, and I can now scale any image to a specified target. Now I shall be attempting to create an equation that will scale to a fixed maximum dimension, interspersed with preparing Sunday lunch. I shall be using Excel to investigate suitable equations before trying them in Affinity.

Please let us know what you come up with for this!

 

It occurs to me there should be some way to use w & h to determine if the image has portrait or landscape proportions so a scale factor could be applied that doesn't distort the image, but I have not yet figured out how to do that.


Affinity Photo 1.7.2, Affinity Designer 1.7.2, Affinity Publisher 1.7.2; macOS High Sierra 10.13.6 iMac (27-inch, Late 2012); 2.9GHz i5 CPU; NVIDIA GeForce GTX 660M; 8GB RAM
Affinity Photo 1.7.2.153 & Affinity Designer 1.7.2.6 for iPad; 6th Generation iPad 32 GB; Apple Pencil; iOS 12.3.1

Share this post


Link to post
Share on other sites
1 hour ago, R C-R said:

Please let us know what you come up with for this!

 

It occurs to me there should be some way to use w & h to determine if the image has portrait or landscape proportions so a scale factor could be applied that doesn't distort the image, but I have not yet figured out how to do that.

Neither have I. What I have been trying is the round function. If this is applied to the aspect ratio, it should yeils a zero (AR<1 or one (AR>1). I can use these as multipliers for other parts of the formula.

However, lunch is ready!


Windows 10, Affinity Photo 1.7 and Designer 1.7, (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

Hmm if the expressions for certain field adjustments are limited here, meaning if they partly don't work for macros, batches, document settings etc. then I wouldn't spend any further time and bother with this. - Instead use something more functional and useful, like for example ImageMagick, which can deal with most image related eventualities and which you can also control out of custom shell scripts and the like. Further when used in shell scripts, you also have generally much better and more powerful control structure support, you can use vars, loop and conditional controls etc. etc. - In short, it offers you much more possibilities here than twiggling around with AP for such things.

Here is just an example which uses the Imagemagick command line program identify to determine the size of an image in pixels, regardless of the file format. This would allow you to determine the horizontal ($ x) and vertical ($ y) resolution, for example to determine portrait or landscape orientation, and then sort them into appropriate Portrait and Landscape folders:

#!/bin/bash
for $f in $@; do
  size=$(identify -format "%G" ${f}) || continue
  x=${size%%x*}
  y=${size##*x}
  if [ "${x}" -le ${y}" ]; then
    mkdir -p Portrait
    mv ${f} Portrait/
  else
    mkdir -p Landscape
    mv ${f} Landscape/
  fi
done 

Of course Imagemagick also has support for various ways of resizing images, just take a look at it's docu and example uses.


☛ Affinity Designer 1.7.1 ◆ Affinity Photo 1.7.1 ◆ OSX El Capitan

Share this post


Link to post
Share on other sites

True, I could probably do as you say. I have not used ImageMagick for a very long time, but it might be a challenge. My current problem has become my current challenge. As I have indicated in a new thread, using Equations is very much hampered by lack of documntation. I have more documentation on ImageMagick than on Equations!


Windows 10, Affinity Photo 1.7 and Designer 1.7, (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
1 hour ago, John Rostron said:

As I have indicated in a new thread, using Equations is very much hampered by lack of documntation.

Same for me. As it stands, it is mostly a matter of trying different things & seeing which ones work, which ones don't, & which ones do something unexpected. 


Affinity Photo 1.7.2, Affinity Designer 1.7.2, Affinity Publisher 1.7.2; macOS High Sierra 10.13.6 iMac (27-inch, Late 2012); 2.9GHz i5 CPU; NVIDIA GeForce GTX 660M; 8GB RAM
Affinity Photo 1.7.2.153 & Affinity Designer 1.7.2.6 for iPad; 6th Generation iPad 32 GB; Apple Pencil; iOS 12.3.1

Share this post


Link to post
Share on other sites

The attached Omega Collider Transformation macro should resize JPEGs to 800px or 600px on their longest side.  That is landscape images will be resized to 800px in width and portrait pictures will be resized to 600px in height.  It can be used on its own or part of a batch job.

The 800px and 600px settings are changeable (within the macro) so you could, for example, resize to 1200px width for Landscape pictures and 900px height for portrait pictures or just to 1000px on the longest size for both landscape and portrait images.

It is designed so that you can mix landscape and portrait images in a batch job to resize to predetermined sizes based on the longest side.

It will not resize images up in size (only reduce them) so your landscape images must be more than 800px width to start with and your portrait images must be more than 600px in height.

I have tested it on what images I have to hand but please check it out on some of your own images to see if it works for you. If you find an image it does not work on please let me know so I can see what is wrong.

The macro contains 9 steps including 2 Equations and I will upload the formulas for them later today if it works OK.

At the moment it is just a concept macro to test the flexibility and unknown potential of the Equation filter.  It was written purely to test the resizing function. What it does to image quality, pixel compression, file sizes, DPI etc I really do not know or care about at this time.

PS At the moment it will not work on images that are squarish shaped.  So it will not work correctly on a 1500px X 1400px image. Basically anything below a width to height ratio of 1.333333  (800px/600px) will not work correctly.  I know why but don't have the time to fix it at the moment so only test it on "real life" landscape and portrait pictures.

( I dare say there may be other configurations that may not work either but I have not tested it for long enough to find them)


PPS Just tested on one panoramic image which appeared to work Ok.  Now off to shovel a ton of snow from my drive so I can get the car out and also find my dog.

omega-collider-transformation-macro-VER3-(beta).afmacro


Due to the fact that Boris Johnson is now our Prime Minister, punctuation, spelling and grammar will never be worried about ever again.  We now have far bigger problems to be concerned about.

Share this post


Link to post
Share on other sites
2 hours ago, carl123 said:

The macro contains 9 steps including 2 Equations and I will upload the formulas for them later today if it works OK.

Even if it does not work perfectly, I would be interested in seeing the equations you used.


Affinity Photo 1.7.2, Affinity Designer 1.7.2, Affinity Publisher 1.7.2; macOS High Sierra 10.13.6 iMac (27-inch, Late 2012); 2.9GHz i5 CPU; NVIDIA GeForce GTX 660M; 8GB RAM
Affinity Photo 1.7.2.153 & Affinity Designer 1.7.2.6 for iPad; 6th Generation iPad 32 GB; Apple Pencil; iOS 12.3.1

Share this post


Link to post
Share on other sites

I think that I have cracked this procedure. The appropriate function to apply to the aspect ratios is floor. For most images floor(h/w)  will give zero for Landscape and One for Portrait, and vice versa for floor(w/h).  However, this will not work in (say) panoramas where the aspect ratio is greater than two: floor(2.3) is 2, so I had to add an extra fudge, the ClampMax function. ClampMax(w/h,1.5) limits the aspect ratio to a maximum of 1.5, which is then floored to 1. There are just two steps in the macro, the Distort filter and the Clip Canvas. (Rather less than the Omega Transform.)

In the Distort > Equations filter, enter the two formulae in the x and y entries:

(x/800)*(h*floor(clampmax(h/w,1.5))+w*floor(clampmax(w/h,1.5)))

(y/800)*(h*floor(clampmax(h/w,1.5))+w*floor(clampmax(w/h,1.5)))

Then Apply, followed by Document > Clip Canvas

Clearly this will only work for a target maximum length of 800. I have recorded it as a macro, and it works on other images. I would  be glad to here from anyone who can tell me how to get the target length in to use as a parameter. The parameter facility within Distort > Equations is just not suitable.

@carl123, Like @R C-R, I would be interested in seeing your equations.

 

Resize to 800.afmacro


Windows 10, Affinity Photo 1.7 and Designer 1.7, (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
18 minutes ago, John Rostron said:

There are just two steps in the macro, the Distort filter and the Clip Canvas. (Rather less than the Omega Transform.)

It's actually an Omega Collider Transformation, I don't think an Omega Transformation on it's own would have worked.

Here are the 9 steps in the macro

1. Unlock the document (just in case it's needed)
2. Run Filters > Distort > Equations using settings shown in Pic1 below
3. Document > Clip Canvas (to get rid of transparent canvas areas)
4. Run Filters > Distort > Equations using settings shown in Pic2 below
5. Document > Clip Canvas (to get rid of transparent canvas areas)
6. Layer > Rasterise  (Clears up some weird behaviour on some image sizes)
7. Select > Alpha Range > Select Partially Transparent - used to select any stray transparent omega pixels on the edge of the image on some image sizes
8. Edit > Fill > Inpainting (apply) - used to inpaint out the stray omega pixels found in step 7
9.  Select > Deselect - just tidying up and deselecting the no longer needed selection

In the 2 screenshots below the numbers 800 and 600 represent the 800px and 600px for the Landscape (width) dimension or the portrait (height) dimension these are the ones you need to change for different resizing options.

 

 

eq1.jpg

eq2.jpg


Due to the fact that Boris Johnson is now our Prime Minister, punctuation, spelling and grammar will never be worried about ever again.  We now have far bigger problems to be concerned about.

Share this post


Link to post
Share on other sites
1 hour ago, John Rostron said:

I would  be glad to here from anyone who can tell me how to get the target length in to use as a parameter. The parameter facility within Distort > Equations is just not suitable.

I have modified your formulas so that the attached macro will present you with a slider to adjust the "a" value which is used to modify the "target length" in the formulas below.

The slider only has a value from 0 to 1 where (in the formulas below) 1 = 1000px

Therefore slide the slider to 0.8 and the pixel value will be 800px, slide to 0.4 and the pixel value will be 400px, etc, etc.

The good news is that the screen updates when you put in new values on the slider but the bad news is the transform panel does not so you can't watch that to set your required image size

Not great, but it shows how the parameters can be used

(x/1000/a)*(h*floor(clampmax(h/w,1.5))+w*floor(clampmax(w/h,1.5)))
(y/1000/a)*(h*floor(clampmax(h/w,1.5))+w*floor(clampmax(w/h,1.5)))

Macro is attached

Resize-to-1000-with-slider.afmacro


Due to the fact that Boris Johnson is now our Prime Minister, punctuation, spelling and grammar will never be worried about ever again.  We now have far bigger problems to be concerned about.

Share this post


Link to post
Share on other sites

@carl123, thank you very much for posting this!

 

One of the annoying things about trying to use equation distortions is illustrated nicely in your screenshots: any formula that can potentially result in a divide by zero error is flagged in red as invalid. Obviously, in real world use h & w would never be zero but since there is no distinction made between invalid syntax & potential divide by zero errors, it makes this otherwise helpful aid less useful than it could be. Also, unless I have misunderstood how they work, formulas using some expressions that could potentially result in a divide by zero error are not flagged, like for example x/(min(a,x)).


Affinity Photo 1.7.2, Affinity Designer 1.7.2, Affinity Publisher 1.7.2; macOS High Sierra 10.13.6 iMac (27-inch, Late 2012); 2.9GHz i5 CPU; NVIDIA GeForce GTX 660M; 8GB RAM
Affinity Photo 1.7.2.153 & Affinity Designer 1.7.2.6 for iPad; 6th Generation iPad 32 GB; Apple Pencil; iOS 12.3.1

Share this post


Link to post
Share on other sites

Yes you learn to ignore the red warnings as they are pointless and unhelpful a lot of the times


Due to the fact that Boris Johnson is now our Prime Minister, punctuation, spelling and grammar will never be worried about ever again.  We now have far bigger problems to be concerned about.

Share this post


Link to post
Share on other sites

@carl123, I have to say that the formulae used in your Distort filters are quite ingenious. I shall have to explore these further. I have ommitted many of the checks that you have included, which is why mine is two steps and yours is nine! Your extra steps are clearly necessary for a production version.

The problem with using the a parameter as you suggest is that it only works properly for a one-off application. I cannot see how you would incorporate it into a batch procss. For my purposes, I would probably write a set of macros for standard target sizes.


Windows 10, Affinity Photo 1.7 and Designer 1.7, (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

I have realized a situaton where my algorithm would break down. If the image is square, then both w and h are equal, and w/h=h/w=1, which means that both floor expressions evaluate to 1. 

Some more work is needed!


Windows 10, Affinity Photo 1.7 and Designer 1.7, (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
2 minutes ago, John Rostron said:

Your extra steps are clearly necessary for a production version.

The #6 step to clear up potential weird behavior is an example of yet another thing that makes using distortion equations harder than it should be. I can't help but think that considerably more documentation and/or official videos would help with this. It is somewhat like for macros documentation -- some things seem almost completely undocumented in the help topics & may or may not be mentioned in a video.


Affinity Photo 1.7.2, Affinity Designer 1.7.2, Affinity Publisher 1.7.2; macOS High Sierra 10.13.6 iMac (27-inch, Late 2012); 2.9GHz i5 CPU; NVIDIA GeForce GTX 660M; 8GB RAM
Affinity Photo 1.7.2.153 & Affinity Designer 1.7.2.6 for iPad; 6th Generation iPad 32 GB; Apple Pencil; iOS 12.3.1

Share this post


Link to post
Share on other sites

I believe that I have resolved the situation where width equals height. In my original formula, the two floor functions ensured that it chose the larger of width or height, but if they were equal it failed. The solution is instead of adding them, take the maximum. Thus:

(x/800)*(h*floor(clampmax(h/w,1.5))+w*floor(clampmax(w/h,1.5)))

becomes:

(x/800)*max(h*floor(clampmax(h/w,1.5)),w*floor(clampmax(w/h,1.5)))

I have incorporated this into the macro, plus the failsafe checks suggested by @carl123. If this passes more testing, I will produce similar macros with varying maximum target sizes, and (if I can work out how) compile them into a macro library. The real test will be: can I use this macro to batch resize a set of images?

 

Resize to 800.afmacro


Windows 10, Affinity Photo 1.7 and Designer 1.7, (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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×