As the questions says. I have large numbers of legacy png files in some databases - converting them to something like avif, or even webp would save tons of space - but it it possible?
I am thinking of something like DT’s own conversion of say, rtf to pdf - the converted records appear alongside the older ones, and (what is terrific) retain labels, tags - which is critical to me.
I know if I use say, GraphicConverter, it will ask where I want to save the (converted) file - and it points to one of the internal structural folders - and I assume I shouldn’t do that.
thanks Christian - was I correct not to save something converted outside to the “c” etc folders?
Although, had a thought - maybe programatically (AS, js) copy the tags, etc to converted files added normally to the respective folders, and then delete the original pngs…
It’s definitely not recommended to save files (or converted ones) directly to the internals of a .dtBase2 database package. This would only cause orphaned files.
You can script GraphicConverter. However, the documentation is a bit terse. And I found that opening a PNG programmatically can cause GC to open a dialog box about transparency – not something one would want in a script, IMO.
And the scripting interface does not support AVIF (yet?). Perhaps talking to the GC people to update their sdef file can fix that.
I’d follow these steps:
get the path property of the DT record,
open it in GC
convert the file in GC saving it to a location outside DT (“/tmp/”, Desktop folder, whatever
import this file into DT
if everything went ok delete the file and move the original image to DT’s trash (where it can be deleted finally later)
Thanks Christian! - v12 now does support AVIF - but you’re saying the scripting doesn’t, I guess just a bit of time for Thorsten to get to it
I’m about to publish my stamps blog (well, a couple of months), and realize the world I knew is no more. PNG are so meh nowadays. So it’s either Webp, AVIF or Image Optimization. I played with them on my images, AVIF wins in terms of quality x size. But also to keep images inside DT, it’s so lightweight.
I will follow the steps you outlined, and report back - again, thanks!
Batching with GraphicConverter has just one drawback for me - I would have to do it DT group by group (unless I also build the logic for distributing, which I am dreading), and right now it’s about ~ 1,000 groups. Of course, I could focus on the heaviest groups, that would make a huge difference.
Ah, I see - but what I really wanted to do is automate saving it to another location and importing it back right where it was. Wonder if setting a folder action?
First off: "/Applications/GraphicConverter 12.app/Contents/MacOS/GraphicConverter 12" -convert IMG_1265.PNG -format AVIF -to IMG-test.avif
on the command line does what you want. You can use that in a doShellScript command with the correct filenames.
Meaning? “Where it was” is some place in the guts of DT. Why would it matter where the images are? And the place will be different because DT uses different folders for image types, eg heic and jpg. So, you can’t import an AVIF image to the same location the PNG originally was stored in.
If you mean “the same group where the original was” – well, just move it to that place. From the scripting dictionary:
importPath method : Import a file or folder (including its subfolders).
importPath text : The POSIX path or file URL of the file or folder.
[to: [Parent] or missing value] : The destination group. Uses incoming group or group selector if not specified.
→ [Record] or missing value : The imported record.
How did you convert to WebP? I use Google’s cwebp command line tool (easy to install via Homebrew); it gives you many options for tweaking things. I haven’t tried AVIF though, so I can’t compare.
Here’s an example AppleScript that calls cwebp with a do shell script like chrillek suggests. It’s written for DT3, so you might need to adjust it a bit.
(Note that I use the folder ~/.tmp, a location that doesn’t exist by default which I created.)
-- Convert selected images to WebP and transfer record properties
-- Using `cwebp` in a shell script
---- Documentation: https://developers.google.com/speed/webp/docs/cwebp
---- Homebrew: https://formulae.brew.sh/formula/webp
set cwebpPath to "/opt/homebrew/bin/cwebp"
set cwebpArgs to " -q 90 -m 6 "
set tmpFolder to "/Users/<USER>/.tmp/" -- Note: This location doesn't exist by default, I created it.
tell application id "DNtp"
set theRecords to selected records whose (type is picture) and (filename does not end with ".webp")
if (count of theRecords) < 1 then
display alert "No image selected"
return
end if
repeat with theRecord in theRecords
-- Get record properties
set {thePath, theName, theGroup, theTags, theLabel, theRating, theComment, cDate} to ¬
{path, name without extension, location group, tags, label, rating, comment, creation date} of theRecord
-- Convert image
set newImgPath to (tmpFolder & theName & ".webp")
do shell script (cwebpPath & cwebpArgs & quoted form of thePath & " -o " & quoted form of newImgPath)
-- Import
set newImg to import newImgPath to theGroup
-- Transfer record properties
set tags of newImg to theTags
set label of newImg to theLabel
set rating of newImg to theRating
set comment of newImg to theComment
set creation date of newImg to cDate
-- Delete temp file
do shell script "rm " & quoted form of newImgPath
end repeat
end tell
I was batch converting to AVIF using GraphicConverter, and could have used webp there - but this is fantastic for the copies of my blog images that are (about 15k, I guess?) inside DT - that’s main main repository. The original images are very high res DSLR scans, and these live inside Lightroom. For creating the blog stories, I am using DT (texts and images, the images used to be png, but these are about 1.2 MB each, and with many, well the whole things starts eating up memory). For the actual posting, I am planning to export fresh AVIF or webp directly from Lightroom’s dng files.
Ah yes, Hans Christian Andersen. Dark stuff, people doing wierd and sometimes bad things and sometimes even getting away with it.
Denmark says “Lets put it on a stamp!”
Ole Sporring and Arne Kühlmann are some of my favorite designers (AK engraved). I find the stamp very deliciously tongue-in-cheek, the dog is amazing “…eyes as big as saucers…”