* Batch change media image extensions

Questions about using and managing media in FH
User avatar
JP Ford
Diamond
Posts: 96
Joined: 16 Feb 2020 14:11
Family Historian: V6.2
Location: Yorkshire, UK
Contact:

Batch change media image extensions

Post by JP Ford »

I am interested in converting all my .JPG media into .PNG format. That is easily done, but my question is; Is there a reasonably easy way to globally edit the extensions of existing media records?

For example, I have media records that point to several files, such as "/media/../filename.JPG". If I convert those images into .PNG format (with the same filenames and paths), how can I mass-replace the JPG in my media records with the new PNG extension?
Researching SORRELL and SORELLE families and associated lines.
https://sorrellnotes.us
User avatar
tatewise
Megastar
Posts: 28436
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Batch change media image extensions

Post by tatewise »

Remember that not only the Media File extension must be changed but also the File Format field.

I have just experimented with Edit > Find... and Edit > Find and Replace...
Edit > Find... did find all those jpg instances in Media records, but Edit > Find and Replace... did not.
It is also possible that jpg occurs in other records. You must also cope with jpeg as a possibility.

I suggest using the Search and Replace plugin which can narrow the scope to Media records and specific fields.
It can also cope with both jpg and jpeg in a single pass. I can supply details when needed.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
JP Ford
Diamond
Posts: 96
Joined: 16 Feb 2020 14:11
Family Historian: V6.2
Location: Yorkshire, UK
Contact:

Re: Batch change media image extensions

Post by JP Ford »

tatewise wrote: 11 Feb 2024 10:53 Remember that not only the Media File extension must be changed but also the File Format field.

I suggest using the Search and Replace plugin which can narrow the scope to Media records and specific fields.
It can also cope with both jpg and jpeg in a single pass. I can supply details when needed.
No jpeg in my files. Thanks Mike! I've taken a look at the Search and Replace plugin and it seems like it might work a treat, but I'm not at all sure about the file format field. I can't see that the plugin will change it.
Researching SORRELL and SORELLE families and associated lines.
https://sorrellnotes.us
User avatar
tatewise
Megastar
Posts: 28436
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Batch change media image extensions

Post by tatewise »

In the plugin, set the Search Scope to Multimedia Records (OBJE).

On the Extra Filters tab, tick the Multimedia Format & Place Hierarchy fields.
( Place Hierarchy is irrelevant as the Search Scope is Multimedia Records only. )
Also, tick the Multimedia Linked File fields and Media files.

I suggest you select LUA Pattern Mode and use Search: jpg$
That anchors the search to the end of the field so only trailing jpg will match.
Replace: png
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Mark1834
Megastar
Posts: 2519
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: Batch change media image extensions

Post by Mark1834 »

Don’t forget that the file format name is jpeg, not jpg. FH is not consistent in how it records format for .jpg files, apparently using either the full name or Microsoft contraction at random. You may well have some jpeg formats even if all your files are .jpg - check the Media tab of the Records Window to be sure.
Mark Draper
User avatar
JP Ford
Diamond
Posts: 96
Joined: 16 Feb 2020 14:11
Family Historian: V6.2
Location: Yorkshire, UK
Contact:

Re: Batch change media image extensions

Post by JP Ford »

Mark1834 wrote: 11 Feb 2024 13:39 Don’t forget that the file format name is jpeg, not jpg. FH is not consistent in how it records format for .jpg files, apparently using either the full name or Microsoft contraction at random. You may well have some jpeg formats even if all your files are .jpg - check the Media tab of the Records Window to be sure.
Does this matter? ime, jpeg and jpg format identification works out the same way. I have some files that have jpg and I've had files that had jpeg (in the file format field). they still open the same way with the same apps, depending on the defaults in the OS. I tend to change them to jpg for consistency. If it matters, I suppose I could change them back, but it doesn't seem to change the way FH or other software handles them.
Researching SORRELL and SORELLE families and associated lines.
https://sorrellnotes.us
User avatar
JP Ford
Diamond
Posts: 96
Joined: 16 Feb 2020 14:11
Family Historian: V6.2
Location: Yorkshire, UK
Contact:

Re: Batch change media image extensions

Post by JP Ford »

tatewise wrote: 11 Feb 2024 13:09 In the plugin, set the Search Scope to Multimedia Records (OBJE).

On the Extra Filters tab, tick the Multimedia Format & Place Hierarchy fields.
( Place Hierarchy is irrelevant as the Search Scope is Multimedia Records only. )
Also, tick the Multimedia Linked File fields and Media files.

I suggest you select LUA Pattern Mode and use Search: jpg$
That anchors the search to the end of the field so only trailing jpg will match.
Replace: png
Okay, did all that and I get 3777 found. I have exactly 1887 .JPG files and 2x1887=3774. As it's finding both the media AND the file type entry, that's complete +3. Not sure I want to worry too much about where the extra 3 changes are coming from... Needless to say, I'm running "Search only" at this point and will do a complete backup before I pull the trigger on this...
Screen-2024-02-11_14-35-14.png
Screen-2024-02-11_14-35-14.png (111.71 KiB) Viewed 2010 times
Researching SORRELL and SORELLE families and associated lines.
https://sorrellnotes.us
User avatar
ADC65
Superstar
Posts: 472
Joined: 09 Jul 2007 10:27
Family Historian: V7

Re: Batch change media image extensions

Post by ADC65 »

JP Ford wrote: 11 Feb 2024 14:40 Does this matter?
If you work entirely within FH it probably doesn't matter, and some other apps may not care either. It does matter to some external apps however, TNG being one of them. It's maybe niche, but it did cause me a headache to sort out at one point so it might be worth being consistent.

I agree with Mark - FH isn't entirely consistent itself. In my experience, it records both JPEG and JPG extensions as JPEG file format.
Adrian Cook
Researching Cook, Summers, Phipps and Bradford, mainly in Wales and the South West of England
User avatar
Mark1834
Megastar
Posts: 2519
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: Batch change media image extensions

Post by Mark1834 »

If you change just .jpg to .png throughout and ignore .jpeg, you’ll end up with files with a .png extension described as jpeg, which is a bit of a bugger’s muddle.

I’m wary of this type of global change unless you know exactly what you are doing, but as with all advice here, on your head be it…
Mark Draper
User avatar
JP Ford
Diamond
Posts: 96
Joined: 16 Feb 2020 14:11
Family Historian: V6.2
Location: Yorkshire, UK
Contact:

Re: Batch change media image extensions

Post by JP Ford »

Mark1834 wrote: 11 Feb 2024 14:54 If you change just .jpg to .png throughout and ignore .jpeg, you’ll end up with files with a .png extension described as jpeg, which is a bit of a bugger’s muddle.

I’m wary of this type of global change unless you know exactly what you are doing, but as with all advice here, on your head be it…
I'm well aware, mate. Thus all the questioning. I will also have done complete backups , etc. before making this big move. As for errant files described as jpeg, I currently have none as I keep them corrected to jpg. It's an easy fix to resolve any stragglers.
Researching SORRELL and SORELLE families and associated lines.
https://sorrellnotes.us
User avatar
JP Ford
Diamond
Posts: 96
Joined: 16 Feb 2020 14:11
Family Historian: V6.2
Location: Yorkshire, UK
Contact:

Re: Batch change media image extensions

Post by JP Ford »

ADC65 wrote: 11 Feb 2024 14:48
JP Ford wrote: 11 Feb 2024 14:40 Does this matter?
It does matter to some external apps however, TNG being one of them. It's maybe niche, but it did cause me a headache to sort out at one point so it might be worth being consistent.
I use TNG directly with FH export and I've not had any issues with format types being jpg. I've maintained "jpg" as my default format type in FH for .jpg images for some time now without issue. FH does seem to randomly assign "jpeg" to some new images, but not all. I just change them to "jpg" when that happens. It's my understanding that they're only historical references to the same format. Back in the day, they were .JPEG images. Then, Windows came along and decided we could only have 3-characters in file extensions... Thus, the .JPG. They're still referring to the JPG image format and modern computers pretty much all understand that. It just tells the software what kind of file it is and what app handles it.
Last edited by JP Ford on 11 Feb 2024 15:11, edited 2 times in total.
Researching SORRELL and SORELLE families and associated lines.
https://sorrellnotes.us
User avatar
Mark1834
Megastar
Posts: 2519
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: Batch change media image extensions

Post by Mark1834 »

Remember that advice is given for the benefit of future readers as well as the original poster (otherwise why bother with a forum search function?), so they need to be fully aware of the potential pitfalls.
Mark Draper
User avatar
Mark1834
Megastar
Posts: 2519
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: Batch change media image extensions

Post by Mark1834 »

JP Ford wrote: 11 Feb 2024 15:10 Then, Windows came along and decided we could only have 3-characters in file extensions... Thus, the .JPG.
Not strictly correct - the 3 character file extension was a feature of the old DOS operating system. Windows 95 fixed that nearly 30 years ago, but such was the dominance of MS at the time, the “feature” has stuck around.
Mark Draper
User avatar
tatewise
Megastar
Posts: 28436
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Batch change media image extensions

Post by tatewise »

The Media File Format jpeg v jpg is a GEDCOM inconsistency:
GEDCOM 5.5 defines MULTIMEDIA_FORMAT:= [ bmp | gif | jpeg | ole | pcx | tiff | wav ]
GEDCOM 5.5.1 defines MULTIMEDIA_FORMAT:= [ bmp | gif | jpg | ole | pcx | tif | wav ]
That is not really anything to do with Microsoft.
Similar confusion in Media file extensions is due to Microsoft.

To cope with both in the Search and Replace plugin use Search: jpe?g$ to make e optional.

To try and identify why the plugin finds 3777 entries, tick just one Extra Filters tab at a time.
That will probably find 1887 .JPG File Link entries and 1890 Multimedia Format entries.
i.e. You have some Media records for non .JPG files but with an erroneous Format field.
Remember the plugin is mainly focused on the Media records, not the files!

Since you will be running the plugin after converting all your files to .PNG none of the actual files will match.
So only the Media record fields for File and Format will get replaced.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
JP Ford
Diamond
Posts: 96
Joined: 16 Feb 2020 14:11
Family Historian: V6.2
Location: Yorkshire, UK
Contact:

Re: Batch change media image extensions

Post by JP Ford »

Mark1834 wrote: 11 Feb 2024 15:24 Not strictly correct - the 3 character file extension was a feature of the old DOS operating system. Windows 95 fixed that nearly 30 years ago, but such was the dominance of MS at the time, the “feature” has stuck around.
Right you are. I should have said “Bill gates came along”. I do have fond memories of running Dos 6 with WordPerfect and Lotus 123. Of course, earlier Windows versions had that same extension feature as well.
Researching SORRELL and SORELLE families and associated lines.
https://sorrellnotes.us
User avatar
JP Ford
Diamond
Posts: 96
Joined: 16 Feb 2020 14:11
Family Historian: V6.2
Location: Yorkshire, UK
Contact:

Re: Batch change media image extensions

Post by JP Ford »

tatewise wrote: 11 Feb 2024 19:11 To try and identify why the plugin finds 3777 entries, tick just one Extra Filters tab at a time.
That will probably find 1887 .JPG File Link entries and 1890 Multimedia Format entries.
i.e. You have some Media records for non .JPG files but with an erroneous Format field.
Remember the plugin is mainly focused on the Media records, not the files!

Since you will be running the plugin after converting all your files to .PNG none of the actual files will match.
So only the Media record fields for File and Format will get replaced.
Okay, so, i attempted this this morning and, in effect, it changed all the file type fields to png, but had no effect on the media records. It gives me the notice that "!! Replacement failed ~ Old value retained !!" on all media object records. I was confused by your last comment above:

"Since you will be running the plugin after converting all your files to .PNG none of the actual files will match.
So only the Media record fields for File and Format will get replaced.
"

I think what you're saying is that the literal filenames will not be changed because they're already *.PNG. Is that why I'm getting the message above????

At any rate, the deed is now done and appears to have been successful. No more jpg media. I used FreeFileSync to accomplish backups of the entire FH project folder and the /media/... structure. My confusion was that I did not expect the Search and Replace plugin to change the actual file names of the image files on disk. When I replaced all my JPG files with the converted PNG's, then ran the plugin, I got the "Failed to replace" errors on every media object record. That confused me, so i did a complete restore of the project folder, then ran the plugin without replacing the JPG files with converted PNG's. The plugin ran without error. When I looked at the media table, I could see that all the JPG records had been changed to PNG, along with the File Type records.

When I checked the media files on the drive, I found that the plugin had indeed changed the extension of all the JPG files to PNG, although they were still JPG format files. A quick run of FreeFileSync to copy the PNG images I previously converted to the project folder and overwrite the "JPG file with PNG extensions" made everything right. So, that was the part of your previous comment that made no sense to me. For those that may venture down this road, just know that if you run the plugin before you replace the JPG files with the converted PNG files, the plugin will run without error and replace the file extensions on all the JPG files with PNG, but they will still be JPG files. You can then just overwrite those files with the converted PNG files.

Once these little details were understood, the process was pretty easy. You just have to be methodical and use the right tools.
Researching SORRELL and SORELLE families and associated lines.
https://sorrellnotes.us
User avatar
tatewise
Megastar
Posts: 28436
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Batch change media image extensions

Post by tatewise »

Usually, it is important for the Media record File Link to sync with the actual Media filename it links to.
They both usually need to be changed together, otherwise the File Links will become broken links.
So that is how the plugin is designed and the option is called Multimedia Linked File fields and Media files.

Changing the Media file extension is a bit more involved because the file itself must be converted.

I also overlooked the fact the plugin insists on changing both the File Link and the actual Media file.
So if the Media files have already been converted to PNG the plugin won't work as I suggested. Sorry!

Nevertheless, you found the workaround by running the plugin first and then converting the files.
BTW: You kept referring to the file type field when I think you meant the Format: field.
When resolving these kinds of issues it helps to use the explicit field names used by FH or post a screenshot.

I'm still a little concerned with the statistics you posted yesterday.
To try and identify why the plugin finds 3777 entries, please try the following steps.
Se the Search box to png$
Run the plugin in Search ONLY mode with only Multimedia Linked File fields and Media files ticked.
I suspect that will find your 1887 File Link entries to the 1887 .PNG Media files.
Run the plugin in Search ONLY mode with only Multimedia Format & Place Hierarchy fields ticked.
I suspect that will find 1890 Multimedia Format entries.
i.e. You have some Media records for non .PNG files but with an erroneous Format field.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
JP Ford
Diamond
Posts: 96
Joined: 16 Feb 2020 14:11
Family Historian: V6.2
Location: Yorkshire, UK
Contact:

Re: Batch change media image extensions

Post by JP Ford »

Changing the Media file extension is a bit more involved because the file itself must be converted.
Yes, this is the part that threw me for a moment. I simply did not expect that the filename itself would be changed. I was expecting that the plugin changed the "records" only. That said, it seems problematic to me that it so willingly changed the extension of the media. That has the potential to have impacts that reach far beyond just the FH project. I do see in the help file that it says "If a Multimedia Linked File field is replaced, the actual Media file path is similarly altered to match.", but I wonder if it might be a good idea to place some extra emphasis on that point.
I also overlooked the fact the plugin insists on changing both the File Link and the actual Media file.
So if the Media files have already been converted to PNG the plugin won't work as I suggested. Sorry! Nevertheless, you found the workaround by running the plugin first and then converting the files.
Luckily, I figured that out pretty quickly, but a less confident user might struggle with that.
BTW: You kept referring to the file type field when I think you meant the Format: field.
Yes, I did.
I'm still a little concerned with the statistics you posted yesterday.
No worries; I figured all that out before I pulled the big lever. As, I recall, there was an issue with an unlinked media, and another strange problem with a media file that had case issues, and a media file that had some problem with the title. Once I resolved those, the plugin resulting numbers were perfect and they remained so throughout the process.

Thanks for your help, Mike!
Researching SORRELL and SORELLE families and associated lines.
https://sorrellnotes.us
User avatar
Mark1834
Megastar
Posts: 2519
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: Batch change media image extensions

Post by Mark1834 »

I think we were typing at the same time... :)

Continuing my theme from yesterday of "how can this go wrong for the novice?", I was trying the same jpg to png conversion on the Sample Project. I too was surprised that the plugin renamed a jpg file to a png file without comment.

If you make the same change in File Explorer, it rightly gives a "Here be dragons" warning that the file might become unusable. Making that change on potentially hundreds or even thousands of files sounds extremely risky.
Mark Draper
User avatar
tatewise
Megastar
Posts: 28436
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Batch change media image extensions

Post by tatewise »

You are both correct. This thread has highlighted some issues that need my attention.
Some scenarios need to be handled better regarding the File LInks, especially regarding the file extension.

I think if the File Link is broken, as would arise if you converted the files from JPG to PNG format beforehand, then perhaps the plugin should allow the Media record File Link to be changed.

Also, the Help page should have extra advice regarding changes to the file extension.
Perhaps the plugin needs some warnings too.

I'm glad you resolved the unexpected plugin statistics.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Mark1834
Megastar
Posts: 2519
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: Batch change media image extensions

Post by Mark1834 »

More worryingly, the plugin also appears to change the file extension of a linked file outside the FH file space without any warning or confirmation challenge.

I'm surprised that that is permitted for a Store plugin...
Mark Draper
User avatar
tatewise
Megastar
Posts: 28436
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Batch change media image extensions

Post by tatewise »

Yes, I've already agreed there are some issues. When originally designed, in response to user requests, I overlooked the implications of the possibility that the file extension might be changed. :oops:
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5510
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Batch change media image extensions

Post by ColeValleyGirl »

Mark1834 wrote: 12 Feb 2024 18:16 More worryingly, the plugin also appears to change the file extension of a linked file outside the FH file space without any warning or confirmation challenge.

I'm surprised that that is permitted for a Store plugin...
Plugins working with Media files have to be able to change things outside the 'FH file space' with the users consent, so let's not get hung up on that, and give Mike space to fix the real (unforeseen) problem.
User avatar
Mark1834
Megastar
Posts: 2519
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: Batch change media image extensions

Post by Mark1834 »

We’ll agree to differ on plugin scope - it’s topical for me as I was making final tweaks to the new Unlinked Media plugin earlier. I will not be adding any functionality to change media files outside the defined project media folder as I consider it too risky (although the more experienced user can take the plugin output and use it outside FH to process files).

However, I’m only an author - there are no defined rules for what plugins can and can’t do, so I’ll stick with what I feel comfortable with, and leave it to the subjective judgement of reviewers to interpret as they see fit.

Agree though on letting Mike get on with the fixes. I hadn’t seen his acknowledgment when I posted my follow-up, and solving issues by committee is never good! :)
Mark Draper
User avatar
JP Ford
Diamond
Posts: 96
Joined: 16 Feb 2020 14:11
Family Historian: V6.2
Location: Yorkshire, UK
Contact:

Re: Batch change media image extensions

Post by JP Ford »

I’d just add that i understand and value the ability of the plugin to alter path/filenames.ext as part of its functionality. My primary concern was that it altered the extension so casually without notice. A novice user might have seen that and assumed that the plugin had actually converted the file to a new format when it had only changed the extension.

My other issue was really user ignorance in that I didn’t expect the file names to be altered. I haven’t looked at the help files for a long time, but i doubt I would have absorbed the single sentence that advised me that it would even if I had.

I’ll trust Mike to do that thing he does to address the issues, but for me, just some bold text warnings and a bit of notice would have resolved my confusion.


Thanks all!!
Researching SORRELL and SORELLE families and associated lines.
https://sorrellnotes.us
Post Reply