nobu1 Posted February 16, 2023 Posted February 16, 2023 I need macro. Is this action the possible with a macro? I want to process 1000 images (in a folder) with one button. 1, It adds a margins (white blank?) up to multiples of 100 to the long size of the rectangular image. 2. It adds a margin (white blank?) to the short size so that the long size is the same. It will be square. 3. Save with jpg image quality 85. sample 1 size 2222x3333 1, 2222x3400(+67) 2, 3400(+1178)x3400 3, save sample 2 size 4444x2222 1, 4500x2222 2, 4500x4500 3, save If possible, I would like to buy it. Photoshop is expensive. Quote
walt.farrell Posted February 16, 2023 Posted February 16, 2023 Macros cannot process multiple files. Nor can they perform a Save operation. However, File > New Batch Job can process multiple files. And it can run one or more macros. The tricky part will be in creating a macro that can operate on images of different sizes or orientations. That can be done, but I will let others who are more qualified comment further on that. Quote -- Walt Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases PC: Desktop: Windows 11 Pro 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 Laptop: Windows 11 Pro 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU. Laptop 2: Windows 11 Pro 24H2, 16GB memory, Snapdragon(R) X Elite - X1E80100 - Qualcomm(R) Oryon(TM) 12 Core CPU 4.01 GHz, Qualcomm(R) Adreno(TM) X1-85 GPU iPad: iPad Pro M1, 12.9": iPadOS 18.3.1, Apple Pencil 2, Magic Keyboard Mac: 2023 M2 MacBook Air 15", 16GB memory, macOS Sequoia 15.0.1
v_kyr Posted February 17, 2023 Posted February 17, 2023 1 hour ago, walt.farrell said: The tricky part will be in creating a macro that can operate on images of different sizes or orientations. Don't forget the first part here, namely to round up the longer determined side to the next hundreds ... Quote > python >>> def roundup(x): ... x -= x % -100 ... return x ... >>> roundup(3333) 3400 >>> roundup(4444) 4500 >>> ... which is a nobrainer to do via Python scripting, as is overall the white space padding to a square for the images too there. walt.farrell 1 Quote ☛ 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
nobu1 Posted February 17, 2023 Author Posted February 17, 2023 >Macros cannot process multiple files. I need a software for macro for this function. I must process 1000 files. 1 file only!? I am confused for buying. Quote
firstdefence Posted February 17, 2023 Posted February 17, 2023 3 hours ago, nobu1 said: >Macros cannot process multiple files. I need a software for macro for this function. I must process 1000 files. 1 file only!? I am confused for buying. Macro's in Affinity are in their infancy and should be considered rudimentary macro's for the time being. You could potentially create a macro to process a single file and add that macro to a batch job as @walt.farrell has mentioned but I'm not sure how effective it would be over 1000s of images. Really, you need a more specific app that is designed for batch processing, one of the best I've seen in a while is Retro Batch Pro, it's node based and so easy a 5 year old kid could use it, I think it will do exactly what you want with ease. I would recommend downloading the Trial and testing it out on a sample batch. I would still consider buying Affinity so you can edit images if you need to, still worth having and hopefully the macro capabilities will improve significantly in the future. I have no affiliation with Flying Meat the people who make Retro Batch, I just think it's a very good app. Quote iMac 27" 2019 Sequoia 15.0 (24A335), iMac 27" Affinity Designer, Photo & Publisher V1 & V2, Adobe, Inkscape, Vectorstyler, Blender, C4D, Sketchup + more... XP-Pen Artist-22E, - iPad Pro 12.9 (Please refrain from licking the screen while using this forum) Affinity Help - Affinity Desktop Tutorials - Feedback - FAQ - most asked questions
v_kyr Posted February 17, 2023 Posted February 17, 2023 6 hours ago, nobu1 said: I need a software for macro for this function. I must process 1000 files. 1 file only!? Usually you don't need a graphics app with good macro capabilities (like PS) at all to do what you want. - You can do that in any better scripting or programming language easily. I show you here a quick turn around with a custom made Python script therefor. I've used just 4 JPG images for demonstration purposes (since I'm lazy, and since it doesn't play any role if you let it process 4, 100 or 1000 files ... here) in an "test_it" subdirectory therefor. Two landscape (long side horizontal) and two portrait (long side vertical) oriented images. Then I let a Python script do all the work by pointing that to the subdirectory. The script looks into that directory, fetches and processes all the JPG-images therein, it adds the wanted rounding up for the individual image w/h and makes a padded square out of those (I used blue for the padding color, so it's better viewable here for demonstrations). Used file sizes before padding: img-horiz-1920.jpg = w x h = 1920 x 1080 px img-horiz-3444.jpg = w x h = 3444 x 1791 px img-vert-2048.jpg = w x h = 1633 x 2048 px img-vert-3333.jpg = w x h = 2561 x 3333 px File sizes after padding: img-horiz-1920.jpg = w x h = 2000 x 2000 px img-horiz-3444.jpg = w x h = 3500 x 3500 px img-vert-2048.jpg = w x h = 2100 x 2100 px img-vert-3333.jpg = w x h = 3400 x 3400 px Here's a screencast of how the Python script operates then ... padding_images.mp4 As initially said, the whole is easy to do with the right tools therefor! firstdefence 1 Quote ☛ 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
laurent32 Posted February 17, 2023 Posted February 17, 2023 Can you share your python script @v_kyr ? Quote MacBook Pro 16 pouces (3456 × 2234), 2021 / Apple M1 Pro / 16 Go / macOS Ventura Version 13.4.1 (22F82) + 31,5 pouces (2560 × 1440) + 27 pouces (1080 × 1920) + iPad (8th generation) / iPadOS 17.2 + Apple Pencil + … Macmini6,2 Quad-Core Intel Core i7 16 Go / macOS Catalina version 10.15.7 (19H2026) MacBookAir6,2 Intel Core i5 double cœur 4 Go / macOS Big Sur version 11.7.7 (20G1345) Licence Universelle Affinity V2 updated to 2.3.0
v_kyr Posted February 17, 2023 Posted February 17, 2023 9 hours ago, laurent32 said: Can you share your python script @v_kyr ? Then the OP probably won't buy APh at all here. - Further it's an from Affinity software completely independent solution and not related in any way here to it. Thus I think I better don't share it here officially for everyone and instead will give it only to individuals on demand via PM. I also usually don't have the time to support that further, or tell people how to install/run/adjust & use it in/with Python etc. - So look after your PM's. laurent32 1 Quote ☛ 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
John Rostron Posted February 17, 2023 Posted February 17, 2023 Have a look here 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
v_kyr Posted February 17, 2023 Posted February 17, 2023 2 hours ago, John Rostron said: Have a look here Well the OP wants to process 1000 images (in a folder) ideally automatically with a one button click. - The images have to be padded in such a way, that they have to be rounded up to the next hundreds on the longer side (w/h) via padding and the shorter side has to be equalled in size via padding here. So the whole image is afterwards padded accordingly to form a square padded image at the end. - And this up to 1000 times! firstdefence 1 Quote ☛ 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
nobu1 Posted February 18, 2023 Author Posted February 18, 2023 I think it is good only the square feature without the margin feature. I will try your support. Thank you! I can't use python due to lack of skill. So I need software. I need to buy software. I will continue to search it. (I don't understand python) I want macro, so I think about purchasing one. This is attractive only for Photoshop function. And this support shows fast and kind. Quote
v_kyr Posted February 18, 2023 Posted February 18, 2023 5 hours ago, nobu1 said: I can't use python due to lack of skill. So I need software. I need to buy software. I will continue to search it. (I don't understand python) Well using for example the more capable PS scripting here (...instead of it's simpler PS actions - .atn files, and so it's just macro based facilities) would also need you to have some more skills/knowledge about Javascript here, since it's based entirely on that. However, whenever you want to do very specific and more advanced custom things here, most standard ready to used tools (...especially most third party GUI tools etc.) won't offer you that overall general flexibility you are after here with your custom purposes (...individual requirements)! - Thus you should really tend to learn, educate yourself and use some much more powerful scripting language (... be it Javascript, Python, Lua, ... or whatever) here, which offers you then nearly to do everything which comes to your mind! - Since you won't find that easily any third party GUI tool, which realy offers to do all that kind of custom/specific things here (... GUI based clicky micky apps have all their limitations, which BTW is also the reason why PS and Co. offer beside much more powerful scripting capabilities here)! Beside the above said, I could also do a GUI app for those requirements you have, BUT I would also charge then money for that, since it's much more expenditure of time to do so, instead of writing quickly a few lines of Python code here! 😄 Quote ☛ 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
h_d Posted February 18, 2023 Posted February 18, 2023 It needs some quite complicated arithmetic which cannot be accomplished with macros in Affinity Photo. Any sort of scripting solution would require you to learn a scripting language. It's also platform-dependent. If you use macOS, then you could AppleScript Image Events or use SIPS through Terminal. Both would work fast, on multiple images, without having to open the images in the user interface. You would need to answer additional questions: for example, do you want to create new, padded versions of the original images or do you want to overwrite the originals? What happens in the extreme (and admittedly unlikely) case of an already square image whose existing dimensions are already a multiple of 100? Do you want the script to work on .jpgs, or .pngs, or .tifs, or a mixture? What if the longest dimension of the original image is an odd number of pixels? It's possible, but there is no straightforward solution. Quote Affinity Photo 2.5.3, Affinity Designer 2.5.3, Affinity Publisher 2.5.3, Mac OSX 14.5, 2018 MacBook Pro 15" Intel.
v_kyr Posted February 18, 2023 Posted February 18, 2023 1 hour ago, h_d said: What happens in the extreme (and admittedly unlikely) case of an already square image whose existing dimensions are already a multiple of 100? Even a good question, I can answer that at least for my Python script solution here. - Nothing will happen, since the image already does meat the final requirements then. - Also when I reprocess all the images, I've once before already processed to be altered accordingly, they won't change anymore here as they do already meet the final requirements. 1 hour ago, h_d said: What if the longest dimension of the original image is an odd number of pixels? That doesn't matter here, due to the always rounding up to the next hundreds, see also my above last image example in the shown test run ... --> img-vert-3333.jpg = w x h = 2561 x 3333 px ... will get ... = 3400 x 3400 px ... therefore you always end up with an even number of pixels! ... def roundup(x): x -= x % -100 return x def pad_image_to_quare_size(image): ... width, height = image.size ... width_max = roundup(width) height_max = roundup(height) ... ... img_padded = Image.new(image.mode, (width_max, height_max), (0, 0, 255)) img_padded.paste(image, (pad_left, pad_top)) return img_padded ... h_d 1 Quote ☛ 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
h_d Posted February 18, 2023 Posted February 18, 2023 16 minutes ago, v_kyr said: therefore you always end up with an even number of pixels! But you have to halve the difference between the original and the padded version. 3400-3333 = 67 Equal padding on either side is 67/2 : 33.5 pixels. How do you add 33.5 pixels (including half a pixel) to each side of the padded image? Quote Affinity Photo 2.5.3, Affinity Designer 2.5.3, Affinity Publisher 2.5.3, Mac OSX 14.5, 2018 MacBook Pro 15" Intel.
v_kyr Posted February 18, 2023 Posted February 18, 2023 4 minutes ago, h_d said: But you have to halve the difference between the original and the padded version. 3400-3333 = 67 Equal padding on either side is 67/2 : 33.5 pixels. How do you add half a pixel to each side of the padded image? ... diff_vert = height_max - h pad_top = diff_vert//2 pad_bottom = diff_vert - pad_top diff_hori = width_max - w pad_left = diff_hori//2 pad_right = diff_hori - pad_left img_padded = Image.new(image.mode, (width_max, height_max), (0, 0, 255)) ### <--- check this ... img_padded.paste(image, (pad_left, pad_top)) ### <--- and this line ... Easy, look at the last two lines above. You create a new image of width_max & height_max which are the already rounded sizes, in some given padding color. Afterwards you place/paste the orig image on the determined left & top padding coordinate orientation of that new image! Quote ☛ 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
h_d Posted February 18, 2023 Posted February 18, 2023 29 minutes ago, v_kyr said: always rounding up I should have thought of that... Quote Affinity Photo 2.5.3, Affinity Designer 2.5.3, Affinity Publisher 2.5.3, Mac OSX 14.5, 2018 MacBook Pro 15" Intel.
v_kyr Posted February 18, 2023 Posted February 18, 2023 Landscape, portrait image orientation isn't really needed to keep track of here, since at the end you either way should have just a square. - Thus you just need to equalize the shorter side value to the longer side value ... ... width_max = roundup(width) height_max = roundup(height) if width_max > height_max: height_max = width_max else: width_max = height_max ... Further you can probably even in AppleScript round up immediately to hundreds easier via something like this ... set imageWidth to (imageWidth - imageWidth mod -100) set imageHeight to (imageHeight - imageHeight mod -100) Quote ☛ 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
nobu1 Posted February 19, 2023 Author Posted February 19, 2023 Hello, I understood it now. I want to add margins on the right and bottom. So odd numbers are no ploblem. It want to leave the original image and make a new image. Quote
v_kyr Posted February 19, 2023 Posted February 19, 2023 11 hours ago, nobu1 said: I understood it now. I want to add margins on the right and bottom. So odd numbers are no ploblem. It want to leave the original image and make a new image. You should more clearly redefine and formulate your requirements here, best also give some before and after image examples which also visually show what you want at the end to come out! - Also tell the OS you would have to use that for! And if you are not that much skilled about scripting languages, you can instead look at ImageMagick which offers very powerful commands for nearly all kind of image editing and image manipulations too. It can of course also pad images, add borders to images ... etc. etc. - And in case you are not the terminal/shell/cmd line guy, then you can also try out a GUI frontend for that "FotoKilof - GUI for ImageMagick". But guess what, that's also made in Python here! 😉 Andreas Scherer 1 Quote ☛ 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
h_d Posted February 19, 2023 Posted February 19, 2023 2 hours ago, v_kyr said: Further you can probably even in AppleScript round up immediately to hundreds easier via something like this ... set imageWidth to (imageWidth - imageWidth mod -100) set imageHeight to (imageHeight - imageHeight mod -100) Sadly no. The following AppleScript works for me (on a single image - it would need to be modified for a folder containing images). set theImageFile to (choose file of type "public.image") as string set whitePadding to {65535, 65535, 65535} tell application "Image Events" launch set theImage to open theImageFile tell theImage set {imageWidth, imageHeight} to dimensions if imageWidth > imageHeight then set longSide to imageWidth set shortSide to imageHeight set imageOrientation to "landscape" else set longSide to imageHeight set shortSide to imageWidth set imageOrientation to "portrait" end if set squareFinal to round ((100 - (text -2 thru -1 of (longSide as string) as integer))) + longSide rounding up set longDiff to squareFinal - longSide set longPadding to round (longDiff / 2) rounding up set firstLongPadded to (longSide + longPadding) set secondLongPadded to (firstLongPadded + longPadding) set shortDiff to squareFinal - shortSide set shortPadding to round (shortDiff / 2) rounding up set firstShortPadded to shortSide + shortPadding set secondShortPadded to firstShortPadded + shortPadding as integer if imageOrientation = "landscape" then pad to dimensions {firstLongPadded, firstShortPadded} with pad color whitePadding save rotate to angle 180 save pad to dimensions {secondLongPadded, secondShortPadded} with pad color whitePadding save rotate to angle 180 save else pad to dimensions {firstShortPadded, firstLongPadded} with pad color whitePadding save rotate to angle 180 save pad to dimensions {secondShortPadded, secondLongPadded} with pad color whitePadding save rotate to angle 180 save end if save end tell close theImage quit end tell It centres the image within the padding rather than placing the padding to the right and below. Which is really annoying as Image Events does that by default - I had to jump through all sorts of hoops to place half the padding on each side of the image. As @v_kyr says, 1 hour ago, v_kyr said: You should more clearly redefine and formulate your requirements And it still adds 1 extra pixel if the longest side of the original image is an odd number of pixels long. More arithmetic needed... Quote Affinity Photo 2.5.3, Affinity Designer 2.5.3, Affinity Publisher 2.5.3, Mac OSX 14.5, 2018 MacBook Pro 15" Intel.
v_kyr Posted February 19, 2023 Posted February 19, 2023 10 hours ago, h_d said: Sadly no. Looks like AppleScript doesn't take the negative sign "-100" from the number into account when performing the math modulo operation, as Python does ... Quote > python3 >>> imagewidth = 1145 >>> imagewidth -= imagewidth % -100 >>> print(imagewidth)1200 >>> imageheight = 1145 >>> imageheight = imageheight - (imageheight % -100) >>> print(imageheight)1200 >>> 1145 % -100-55 >>> 1145 % 10045 But it should also be doable in AppleScript instead this way then ... h_d 1 Quote ☛ 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
v_kyr Posted February 20, 2023 Posted February 20, 2023 Here's my above mentioned Py-script, which iterates over all image files in a given directory path and pads those images then. - Usage is: Quote > python3 padding.py -h || python3 padding.py --help usage: padding.py [-h] dirpath positional arguments: dirpath the directory path to look for images options: -h, --help show this help message and exit > python3 padding.py test_it/ Using directory path: test_it/ Processing: test_it/img-horiz-1920.jpg Processing: test_it/img-horiz-3334.jpg Processing: test_it/img-vert-2048.jpg Processing: test_it/img-vert-3333.jpg ... padding.py laurent32 1 Quote ☛ 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
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.