John Rostron Posted December 15, 2017 Posted December 15, 2017 (edited) In another thread in Questions, I have been discussing with others how to write a macro that will resize an image so that the longest side is a fixed value. For example, if I resize a 4000x3000 image to maximum of 800, it will give a 800x600 image. For a portrait image, the image will become 600X800. After many iterations, I came up with a set of macros included here in a macro library: Resize to fixed max size.afmacros, which is attached here. This includes five macros: Resize to 640 max Resize to 800 max Resize to 1280 max Resize to 1600 max Resize to variable max side The first four will resize any image to the designated maximum size. The last one includes a parameter which allows you to partly-specify the target size. The default target size is 2000px, but for any other value (up to a maximum of 4000, use the pop-up to adjust. The value of the parameter is the desired maximum size divided by 4000. A convenient way of specifying the final maximum edge size is to enter a fraction. If your target is (say) 800px then, in the parameter box (not the slider), enter 800/4000. If your target is 3200, enter 3200/4000. I have given technical details of the macro in subsequent messages in this thread. EDIT: This is a revised version of the macros (as of 2nd November 2018). For details of the changes, see the item below which gives the macro details). The changes were in response to a user who found that if he cropped the image first, the macro did not work. Resize to fixed maximum size.afmacros Edited November 3, 2018 by John Rostron Modified to improve useability nodeus, affwin, MEB and 3 others 6 Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
John Rostron Posted December 15, 2017 Author Posted December 15, 2017 Some technical details about these macros. In the thread mentioned I had helpful comments and advice from @carl123, @R C-R and @v_kyr. The problem with writing such a macro is to identify the longest side. The basic formula I used for this is:max(w,h) which takes the larger of the two sides, and selects the width or height accordingly. I had to use the Distort > Equations filter to implement this, we have found that Document > Resize and the Transform functions will not work in macros. The final equations for x and y in the Distort filter are:(x/800)*max(h,w) (y/800)*max(h,w) The final macro, with the parameter is: (x/(4000*a))*max(h,w) (y/(4000*a))*max(h,w) Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
Gnobelix Posted December 15, 2017 Posted December 15, 2017 Hello John, Thanks for sharing, I love the little macros that make the job easier John Rostron 1 Quote Affinity Photo 2.5: Affinity Photo 1.10.6: Affinity Designer 2.5: Affinity Designer 1.10.6: Affinity Publisher 2.5: Affinity Publisher 1.10.6: Windows 11 Pro (Version 24H2 Build (26100.3037)
affwin Posted December 15, 2017 Posted December 15, 2017 Hello, that's a very helpful macro. Especially for use in batch mode.Thanks for that.Dieter Quote Germany, Affinity Photo WIN 1.7 , LR6, WIN10
John Rostron Posted December 15, 2017 Author Posted December 15, 2017 More technical details: When we were looking at various algorithms, @carl123 came up with an ingenious and elegant method for resizing. Instead of using separate x and y coordinates (Cartesian coordinates), he proposed using polar coordinates, which essentially would scale everything from the origin (0,0) of the image. This would render finding the longest side redundant. Unfortunately we found that if the image side was an odd number of pixels, the scaling in the Equations engine rounded the answer up, so that it became one more than the target size! There are workarounds for this, but it mean that an implementation was not as simple as the Cartesian coordinate algorithm. Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
John Rostron Posted December 15, 2017 Author Posted December 15, 2017 (edited) Do it yourself: If you want to write your own version of this macro for your favourite maximum size, these are the steps: Layer > Unlock Layer > Rasterize and TrimFilter > Distort > Equations Enter the following in the x and y fields, substituting your own maximum size, then Apply (x/MAXSIZE)*max(h,w) (y/MAXSIZE)*max(h,w)Document > Clip Canvas Layer > RasterizeSelect > Alpha Range > Select Partially Transparent Edit > Fill> Inpainting Select > Deselect I thank @carl123 for the last four steps. EDIT: These macros have been edited to add the first two steps. Unlocking is necessary, but I had not previously included it in the Macro. The Rasterize step is necessary if the image has been cropped previously. EDIT 2: I have amended step 2 to use Rasterize and Trim (rather than just Rasterize). This is new in 1.7. Edited September 24, 2019 by John Rostron Modified to improve useability and updated step 2 HVDB Photography, affwin and Przemysław 2 1 Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
Traveler Posted February 21, 2018 Posted February 21, 2018 John, thanks for the information on how to do this, complicated as it is. Do you happen to know if this method allows to specify the resizing method (i.e. bilinear, bicubic, etc.)? If not, do you know what the default resizing method is? Quote
John Rostron Posted February 22, 2018 Author Posted February 22, 2018 14 hours ago, Traveler said: John, thanks for the information on how to do this, complicated as it is. Do you happen to know if this method allows to specify the resizing method (i.e. bilinear, bicubic, etc.)? If not, do you know what the default resizing method is? Fraid not. The Distort filter offers no options for a resizing method. You can write a macro for Document > Resize, with a specific size and include the resizing method of your choice, but you do not have the flexibility of the Equations filter. John Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
Traveler Posted February 22, 2018 Posted February 22, 2018 7 hours ago, John Rostron said: Fraid not. The Distort filter offers no options for a resizing method. You can write a macro for Document > Resize, with a specific size and include the resizing method of your choice, but you do not have the flexibility of the Equations filter. John Thanks for clarifying, John. John Rostron 1 Quote
TomM1 Posted September 29, 2018 Posted September 29, 2018 On 12/15/2017 at 8:05 AM, John Rostron said: In another thread in Questions, I have been discussing with others how to write a macro that will resize an image so that the longest side is a fixed value. For example, if I resize a 4000x3000 image to maximum of 800, it will give a 800x600 image. For a portrait image, the image will become 600X800. After many iterations, I came up with a set of macros included here in a macro library: Resize to fixed max size.afmacros, which is attached here. This includes five macros: Resize to 640 max Resize to 800 max Resize to 1280 max Resize to 1600 max Resize to variable max side The first four will resize any image to the designated maximum size. The last one includes a parameter which allows you to partly-specify the target size. The default target size is 2000px, but for any other size you need to right-click on this macro and choose edit, then click on the cogwheel next to the Equations entry. Parameter 1 is set to approximately 0.5. This is a multiplier of 4000, so 4000*0.5 gives the default size of 2000. Changing this value scales the maximum size (0.3 gives 1200, 0.75 gives 3000 etc). I have given technical details of the macro in subsequent messages in this thread. These resize macros don't seem to work on a cropped image. Quote website Mac mini (2018) 3.2 GHz Intel Core i7 64 GB • Radeon Pro 580 8 GB • macOS Monterey
TomM1 Posted September 29, 2018 Posted September 29, 2018 Post removed Quote website Mac mini (2018) 3.2 GHz Intel Core i7 64 GB • Radeon Pro 580 8 GB • macOS Monterey
John Rostron Posted September 29, 2018 Author Posted September 29, 2018 1 minute ago, TomM1 said: These resize macros don't seem to work on a cropped image. This is what the Document > Clip Canvas and Layer > Rasterize lines were supposed to resolve. I was having your problem unti I inserted them, after which it worked OK. I have just reinstalled Windows 10, so I am not able to test this myself at present. Could you try running those two lines first before the macro? John Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
TomM1 Posted September 30, 2018 Posted September 30, 2018 Hard to believe AP has no photoshop-like fit image command. Climber 1 Quote website Mac mini (2018) 3.2 GHz Intel Core i7 64 GB • Radeon Pro 580 8 GB • macOS Monterey
TomM1 Posted September 30, 2018 Posted September 30, 2018 On 9/29/2018 at 11:49 AM, John Rostron said: This is what the Document > Clip Canvas and Layer > Rasterize lines were supposed to resolve. I was having your problem unti I inserted them, after which it worked OK. I have just reinstalled Windows 10, so I am not able to test this myself at present. Could you try running those two lines first before the macro? John I don’t know to do what you suggest. Quote website Mac mini (2018) 3.2 GHz Intel Core i7 64 GB • Radeon Pro 580 8 GB • macOS Monterey
John Rostron Posted September 30, 2018 Author Posted September 30, 2018 2 minutes ago, TomM1 said: I don’t know to do what you suggest. With your cropped pixel layer selected, first apply Document > Clip Canvas and then apply Layer > Rasterize and then apply the macro. I have not yet reinstalled Affinity on my computer so I cannot try it out myself yet. John Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
TomM1 Posted September 30, 2018 Posted September 30, 2018 Document > Clip Canvas, uncrops the image. Quote website Mac mini (2018) 3.2 GHz Intel Core i7 64 GB • Radeon Pro 580 8 GB • macOS Monterey
John Rostron Posted October 25, 2018 Author Posted October 25, 2018 On 9/29/2018 at 6:40 PM, TomM1 said: These resize macros don't seem to work on a cropped image. @TomM1, I have not forgotten you. My re-install of Windows and Affinity lost my own macro files. Fortunately I had posted most of them here so I should be able to retrieve them. I should be able to attend to them in the next few days. Could you post a cropped image that you have been having problems with (as an .afphoto file)? John Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
John Rostron Posted October 27, 2018 Author Posted October 27, 2018 On 9/29/2018 at 6:40 PM, TomM1 said: These resize macros don't seem to work on a cropped image. You are correct. All my experimentation was on newly loaded images. I have found that if I crop the image, then apply the macro, it applies the resizing to the cropped area, but then adds back the area around the crop! The solution is to Rasterize before applying the macro. It then works as expected. I will modify the macros to include this Rasterize step and re-post. John Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
John Rostron Posted October 28, 2018 Author Posted October 28, 2018 18 hours ago, John Rostron said: I will modify the macros to include this Rasterize step and re-post. This has now been done. The macro set in the first post now includes these amendments. John Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
Zenfoto Posted February 15, 2020 Posted February 15, 2020 Does this Macro resize the original files or non-destructively create resized copies? Quote
John Rostron Posted February 16, 2020 Author Posted February 16, 2020 8 hours ago, Zenfoto said: Does this Macro resize the original files or non-destructively create resized copies? The macro works on the current (Pixel) layer, so it is destructive. I have not tried it on multi-layered objects. You will need to save or export your image under a different name. John Zenfoto 1 Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
Grumpy1954 Posted July 13, 2020 Posted July 13, 2020 Thank you for your work on these macros. When I downloaded them it turned out that they were not quite what I was after, but I still think that thanks are due for time and expertise spent in their creation. John Rostron 1 Quote
JIPJIP Posted February 10, 2024 Posted February 10, 2024 Hi, I don't know if there is a more recent topic about this subject. Is there now (2024) a way to resize an image AND specify the method (bilinear, bicubic, etc ..;) in a macro ? Thanx Quote
JIPJIP Posted February 10, 2024 Posted February 10, 2024 Ohh, i forgot : and having no problem with images with different sizes. Quote
John Rostron Posted February 11, 2024 Author Posted February 11, 2024 14 hours ago, JIPJIP said: Hi, I don't know if there is a more recent topic about this subject. Is there now (2024) a way to resize an image AND specify the method (bilinear, bicubic, etc ..;) in a macro ? Thanx You can specify the resampling algorithm using Document > Resize in a macro, but the saved macro always uses the original image propeties when running, not those of the image you apply it to. Using Equations avoids this problem, but you cannot specify the resampling algorthm. John Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
Recommended Posts
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.