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

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.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

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
Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases
PC:
    Desktop:  Windows 11 Pro, version 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 

    Laptop:  Windows 11 Pro, version 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU.
iPad:  iPad Pro M1, 12.9": iPadOS 17.4.1, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.4.1

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

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.

All 3 1.10.8, & all 3 V2.4.1 Mac apps; 2020 iMac 27"; 3.8GHz i7, Radeon Pro 5700, 32GB RAM; macOS 10.15.7
Affinity Photo 
1.10.8; Affinity Designer 1.108; & all 3 V2 apps for iPad; 6th Generation iPad 32 GB; Apple Pencil; iPadOS 15.7

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

All 3 1.10.8, & all 3 V2.4.1 Mac apps; 2020 iMac 27"; 3.8GHz i7, Radeon Pro 5700, 32GB RAM; macOS 10.15.7
Affinity Photo 
1.10.8; Affinity Designer 1.108; & all 3 V2 apps for iPad; 6th Generation iPad 32 GB; Apple Pencil; iPadOS 15.7

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

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.

All 3 1.10.8, & all 3 V2.4.1 Mac apps; 2020 iMac 27"; 3.8GHz i7, Radeon Pro 5700, 32GB RAM; macOS 10.15.7
Affinity Photo 
1.10.8; Affinity Designer 1.108; & all 3 V2 apps for iPad; 6th Generation iPad 32 GB; Apple Pencil; iPadOS 15.7

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

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.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

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

All 3 1.10.8, & all 3 V2.4.1 Mac apps; 2020 iMac 27"; 3.8GHz i7, Radeon Pro 5700, 32GB RAM; macOS 10.15.7
Affinity Photo 
1.10.8; Affinity Designer 1.108; & all 3 V2 apps for iPad; 6th Generation iPad 32 GB; Apple Pencil; iPadOS 15.7

Link to comment
Share on other sites

Well the Affinity apps online help system list those always under:

Though AP here offers some few more than AD for the Advanced mathematical expressions!

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

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

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

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.

All 3 1.10.8, & all 3 V2.4.1 Mac apps; 2020 iMac 27"; 3.8GHz i7, Radeon Pro 5700, 32GB RAM; macOS 10.15.7
Affinity Photo 
1.10.8; Affinity Designer 1.108; & all 3 V2 apps for iPad; 6th Generation iPad 32 GB; Apple Pencil; iPadOS 15.7

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

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

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

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

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

@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)).

All 3 1.10.8, & all 3 V2.4.1 Mac apps; 2020 iMac 27"; 3.8GHz i7, Radeon Pro 5700, 32GB RAM; macOS 10.15.7
Affinity Photo 
1.10.8; Affinity Designer 1.108; & all 3 V2 apps for iPad; 6th Generation iPad 32 GB; Apple Pencil; iPadOS 15.7

Link to comment
Share on other sites

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

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

@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.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

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.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 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.

All 3 1.10.8, & all 3 V2.4.1 Mac apps; 2020 iMac 27"; 3.8GHz i7, Radeon Pro 5700, 32GB RAM; macOS 10.15.7
Affinity Photo 
1.10.8; Affinity Designer 1.108; & all 3 V2 apps for iPad; 6th Generation iPad 32 GB; Apple Pencil; iPadOS 15.7

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