laurent32 Posted June 24, 2023 Share Posted June 24, 2023 Hi all, I'm looking for a way to automatically import images in photo from a text list of URLs… just like the title says ! And even more, I wish I could mix that within a macro to (for example) export all the files with a given width and a new computed name. Also, I think I could do that with macOS shortcuts app but I've never used it so… if someone could help… I'd be very grateful ! Thanks Edit : it might also be done with a small python routine ??? 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 Link to comment Share on other sites More sharing options...
v_kyr Posted June 24, 2023 Share Posted June 24, 2023 Well here (for me) some of the needed preconditions are not clearly defined in their meanings ... Import - So just opening several images in/as own APh documents, or instead placing images into one and the same document? URLs - Their location, are those URLs pointing to the local file system, or do they have instead to be some from the internet to be accessed (aka downloadable first) images? BTW, if it's overall just in order to have a list of some files to open, resize their width or height to a given size and then resave them under a new name, then one don't need any Affinity product at all here to do so. As it would be more of an unnecessary hassle (too cumbersome, inefficient) trying to do this with Affinity. 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 Link to comment Share on other sites More sharing options...
walt.farrell Posted June 24, 2023 Share Posted June 24, 2023 2 hours ago, laurent32 said: And even more, I wish I could mix that within a macro to (for example) export all the files with a given width and a new computed name. You cannot do that with macros. Are you asking a question ("Can I do this?")? Or are you making a request to add these functions? If you're making a request, you need to do that in the Feedback section of the forum, as that's where the Serif planners look for them,. laurent32 1 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.1, Apple Pencil 2, Magic Keyboard Mac: 2023 M2 MacBook Air 15", 16GB memory, macOS Sequoia 15.0.1 Link to comment Share on other sites More sharing options...
laurent32 Posted June 24, 2023 Author Share Posted June 24, 2023 @v_kyr Hi, sorry for being unclear, yes I meant opening as standalone documents (if I have 100 URLs then I'll get 100 photo files) and yes I meant web URLs pointing to jpg files (or other formats) that are downloadable. I agree that for plenty of file it might be better to have a python routine but I don't know how to create that routine… @walt.farrell Hi, yes I'm asking if I can already do that right now, and if not, yes I'll ask for some feature request because I'm missing that feature. I wish we could open a file via it's link on the web. Thanks both for answering. 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 Link to comment Share on other sites More sharing options...
David in Яuislip Posted June 24, 2023 Share Posted June 24, 2023 You can use urls in New stack or New batch job dialogs but they need to be added one at a time So with a text file open you could cut each row and paste it into Affinity. 100 files is doable, I'd baulk at 1000 I'd sooner wrie a Python script to download them but if you're unable to do that the above is an idea Quote Microsoft Windows 11 Home, Intel i7-1360P 2.20 GHz, 32 GB RAM, 1TB SSD, Intel Iris Xe Affinity Photo - 24/05/20, Affinity Publisher - 06/12/20, KTM Superduke - 27/09/10 Link to comment Share on other sites More sharing options...
v_kyr Posted June 24, 2023 Share Posted June 24, 2023 Well some Python script can do all of that, though you would have to more clearly specifiy how the text file should overall look like, since there are different possibilities here to handle URLs from text files. For example, let's say we're having the following text in a file "text.txt" ... Quote Nowadays you can learn almost anything about Affinity software by just visiting https://forum.affinity.serif.com . But if you are completely new to computers or internet then first you need to learn those fundamentals. Next you can visit a good Affinity e-learning site like - https://affinityspotlight.com to learn further on a variety of Affinity subjects. ... then the following used regexp in an Python script ... import re with open("text.txt") as file: for line in file: urls = re.findall('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', line) print(urls) ... when executed (> python3 geturl.py test.txt) will get/match the URLs and print them out ... ['https://forum.affinity.serif.com'] ['https://affinityspotlight.com'] BUT if you are going to make a text based control file something like a simple CSV like text file might here be more suitable, like for example ... Quote # URL; NEW WIDTH SIZE; NEWFILENAMEhttps://whereever.com/image1.png; 800; myimage1.pnghttps://whereever.com/image5.png; 1024; myimage2.png ... ... that would also be easy to read/parse, handle and perform within a Python script. And fetching and holding some image via an given URL in Python (for further processing) could be as easy as ... from PIL import Image import requests im = Image.open(requests.get(url, stream=True).raw) ... the above oneliner fetches an image from a given URL and holds that inside an "im" image variable. So you can do now something with that image like resizing it etc. And at the end of your "im" image manipulation you would write that image back to disk under/as some new name. So the overall steps to take in/with Py here are ... Define yourself some suitable text control file structure Parse/read that text control file with Py, looping over it line for line in order to get/hold each line entry (the URL, new width value, new file name text) ... With the on the fly got line column entries perform the needed operations, aka fetch/download the URL as an image, resize that fetched image, save the modified image under some new name ... whatever else you want or need to do 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 Link to comment Share on other sites More sharing options...
laurent32 Posted June 24, 2023 Author Share Posted June 24, 2023 43 minutes ago, v_kyr said: https://whereever.com/image1.png; 800; myimage1.pnghttps://whereever.com/image5.png; 1024; myimage2.png That's exactly were I am, I exported my csv file from Filemaker and now I'd want to go to the next step… My son is on holiday right now, but I'm sure he will build or find some little python code for me… That's why I was looking for any other ideas… 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 Link to comment Share on other sites More sharing options...
laurent32 Posted June 24, 2023 Author Share Posted June 24, 2023 1 hour ago, David in Яuislip said: You can use urls in New stack or New batch job dialogs but they need to be added one at a time So with a text file open you could cut each row and paste it into Affinity. 100 files is doable, I'd baulk at 1000 I didn't know about stack, I'll look after that too. Now, I regularly get much more then 100, that's why I must find a good solution… Thanks for your answer. 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 Link to comment Share on other sites More sharing options...
v_kyr Posted June 24, 2023 Share Posted June 24, 2023 5 hours ago, laurent32 said: That's exactly were I am, I exported my csv file from Filemaker and now I'd want to go to the next step… My son is on holiday right now, but I'm sure he will build or find some little python code for me… That's why I was looking for any other ideas… Ok found some 10 minutes spare left time for this, in order to look how to quickly maybe do that with some Python 3 script which takes the values from a CSV file then. Actually a CSV to use has to be setup like this, aka ... --> the_url;width;save_filename ... though you can change that in the Python code to some other CSV delimiter char, or instead also pass the delimiter char to use over as an argument too (you have then to change/add argparse code for the later, passing over the CSV delimiter as an argument) ... https://cdn.pixabay.com/photo/2013/07/18/20/26/sea-164989_960_720.jpg;800;image1.jpg https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_960_720.jpg;600;image2.jpg https://cdn.pixabay.com/photo/2013/02/21/19/06/drink-84533_960_720.jpg;600;image3.jpg ... you have to make sure that the initial fetched images are size-wise big enough when resized for the width here, as the used Python module "resizeimage" will otherwise complain about that when running the script! For this common Python 3 script to work, your Python 3 installment will have to use some third-party modules (argparse, PIL/PILLOW, resizeimage ...). Thus you would have to install those first here into your Python 3 environment, in case or if they are not already installed there ... pip install argparse pip install Pillow pip install python-resize-image pip install requests Here's a short Python 3 script which should do what you're after (as far as I understood your needs) ... #!/usr/bin/env python3 # -*- coding: utf-8 -*- import argparse import csv from PIL import Image from resizeimage import resizeimage import requests def perform_csv_row(row): # This function gets the values (url, width, filename) from a CSV row and then # - fetches the URL as an image # - sizes the image proportional to the given width # - saves the resulting image under a given new name the_url = row[0] the_width = int(row[1]) the_name = row[2] image = Image.open(requests.get(the_url, stream=True).raw) the_image = resizeimage.resize_width(image, the_width) the_image.save(the_name, image.format) # Create an argument parser parser = argparse.ArgumentParser() # Add an argument parser.add_argument('--csvfilename', type=str, required=True) # Parse the argument args = parser.parse_args() with open(args.csvfilename, 'r') as file: csvreader = csv.reader(file, delimiter=';') for row in csvreader: perform_csv_row(row) You would call that py script from a MacOS cmd shell (iTerm2.app or the MacOS supplied Terminal.app) the following way ... Quote > python3 proc_image_urls.py --csvfilename test.csv Here are the short Python 3 script and a little test.csv file ... proc_image_urls.py test.csv 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 Link to comment Share on other sites More sharing options...
carl123 Posted June 25, 2023 Share Posted June 25, 2023 16 hours ago, laurent32 said: Now, I regularly get much more then 100, that's why I must find a good solution… Many utilities/programs can download a list of image URLs to a folder. Once downloaded you can process all the images to .afphoto format using APhoto's batch job and also specify the file size and use any macros you want If you have to do this regularly just find a utility/program to first copy all images URLs to a folder. It's probably the easiest way to do this laurent32 1 Quote 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 More sharing options...
David in Яuislip Posted June 25, 2023 Share Posted June 25, 2023 Here's my contribution for forum members that have the same need Place the python file into a new folder, add ImageList.txt containing the image urls, one per line, no quotes Run ImageURLs.py Then use Photo to process the files Of course Python can be used to manipulate the image but that's outwith the scope of this forum Use, abuse, modify or ignore 🙂 ImageURLs.py laurent32 1 Quote Microsoft Windows 11 Home, Intel i7-1360P 2.20 GHz, 32 GB RAM, 1TB SSD, Intel Iris Xe Affinity Photo - 24/05/20, Affinity Publisher - 06/12/20, KTM Superduke - 27/09/10 Link to comment Share on other sites More sharing options...
laurent32 Posted June 25, 2023 Author Share Posted June 25, 2023 14 hours ago, v_kyr said: Ok found some 10 minutes spare left time for this, in order to look how to quickly maybe do that with some Python 3 script which takes the values from a CSV file then. I'm so grateful, thanks @v_kyr I'm going to have it a go right now !! 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 Link to comment Share on other sites More sharing options...
laurent32 Posted June 25, 2023 Author Share Posted June 25, 2023 2 hours ago, carl123 said: Many utilities/programs can download a list of image URLs to a folder Thanks @carl123 , are you on Mac or Windows ? Can you share some names ? 2 hours ago, carl123 said: If you have to do this regularly just find a utility/program to first copy all images URLs to a folder. It's probably the easiest way to do this I think so too, @v_kyr just gave me some code that I'm going to use right now… 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 Link to comment Share on other sites More sharing options...
laurent32 Posted June 25, 2023 Author Share Posted June 25, 2023 57 minutes ago, David in Яuislip said: Use, abuse, modify or ignore 🙂 Thanks @David in Яuislip !! 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 Link to comment Share on other sites More sharing options...
laurent32 Posted June 25, 2023 Author Share Posted June 25, 2023 You guys are great !!! 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 Link to comment Share on other sites More sharing options...
carl123 Posted June 25, 2023 Share Posted June 25, 2023 44 minutes ago, laurent32 said: Thanks @carl123 , are you on Mac or Windows ? Can you share some names ? Sorry, I'm on Windows, don't know any for mac Quote 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 More sharing options...
v_kyr Posted June 25, 2023 Share Posted June 25, 2023 5 hours ago, laurent32 said: Can you share some names ? Well on any Unix based and even for Win based systems, there's "Wget" ... Gnu Wget Gnu Wget manual Wget man page MacOS Install wget network downloader utility Windows binaries of GNU Wget 1.21.3 ... which has advantages over GUI based frontends/tools here, as it can be (re)used in any batch/shell/script languages. For Win based systems the MS Powershell has/offers it's own alternatives to Wget like for example Invoke-WebRequest! There are of course also GUI frontends to Wget and similar GUI tools ... AWGG Progressive Downloader (MacOS) WebUI-Aria2 VisualWGet (Win) WinWGet (Win) ... and so on ... 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 Link to comment Share on other sites More sharing options...
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.