Skip to content

Instantly share code, notes, and snippets.

@rbrito
Forked from Iunius118/gimp_autosave.py
Created December 7, 2018 01:27
Show Gist options
  • Save rbrito/e57c87d5376fd56113df058abf71bdf3 to your computer and use it in GitHub Desktop.
Save rbrito/e57c87d5376fd56113df058abf71bdf3 to your computer and use it in GitHub Desktop.
Auto save plug-in for GIMP [2.8, 2.9]
#!/usr/bin/env python
# Original (by yahvuu): http://www.gimpusers.com/forums/gimp-developer/11718-autosave-plugin
import tempfile, os
from time import *
from gimpfu import *
def autosave(image, layer):
backupInterval = 10 * 60
backupFiles = {}
print "Autosave activated"
while 1:
sleep(backupInterval)
print ctime(time())
curImages = {}
for k in gimp.image_list():
curImages[k.ID] = k
curIDs = curImages.keys()
oldIDs = backupFiles.keys()
newIDs = [x for x in curIDs if x not in oldIDs]; delIDs = [x for x in oldIDs if x not in curIDs];
# create (empty) backup files for new images
for id in newIDs:
prefix = 'gimpbackup-ID' + str(id) + '-'
fn = tempfile.mkstemp(prefix = prefix, suffix = '.xcf')
os.close(fn[0])
backupFiles[id] = fn[1]
# remove closed images' backups
for id in delIDs:
filename = backupFiles[id]
del(backupFiles[id])
try:
os.remove(filename)
except:
print "ERROR: ", sys.exc_info()[0]
# backup images
for id, filename in backupFiles.iteritems():
img = curImages[id]
try:
print "saving " + img.name + '-' + str(id) + ' to ' + filename
pdb.gimp_xcf_save(1, img, img.active_drawable, filename, filename)
except:
print "ERROR: ", sys.exc_info()[0]
register(
"autosave",
"Autosave dirty hack",
"Periodically saves all opened images to a %temp% directory",
"public domain",
"public domain",
"2016",
"<Image>/File/Activate Autosave",
"*",
[],
[],
autosave)
main()
@s0urc3ray
Copy link

Thanks! Lost my work twice in the past few days, power cut and then a crash today :(
I find it absurd that GIMP does not have this built in yet, the bug report requesting auto-save is still open with comments from 15 years ago!

@ErtYwek
Copy link

ErtYwek commented Feb 21, 2020

Where does it save "all opened images"? Autosave function should be implemented in gimp cause its crash very often when you edit big [ 100mb+] xcf files

I find it absurd that GIMP does not have this built in yet, the bug report requesting auto-save is still open with comments from 15 years ago!

But still remember that GNU Image Manipulation Program is free of charge

@crogonint
Copy link

Remember, free isn't worth it when it costs you precious time.
Over and over again.
For sixteen years.

@crogonint
Copy link

So.. this plug-in DOES go in the /home/username/.gimp-2.8/plug-ins/ folder

You do not have to jump through hoops downloading obscure packages to figure out how to register it in Gimp.
You do not have to do a bunch of top secret command crap in terminal.
You do not have to hack it in to the system directory or install a system Python version.
Once you have it in the proper folder, go to the file properties for the script and make it executable.
That is all.
God alone knows why.

If you still don't see it on the FIle menu the next time you open Gimp, close Gimp, go to the /home/username/.gimp-2.8/ folder and delete the pluginrc file. open Gimp again, and it will rediscover all of the add-ons.

Ta-Da!

@wolfbeaumont
Copy link

Where is the autosave storing these temporary images?

@crogonint
Copy link

FYI, I had it out with the GIMP developers a couple of months ago. Bottom line.. they have no intention of EVER making auto-save a priority.
They actually banned me from the GIT over there.
It will never get done.

People will need to keep this precious little script updated and running, or the capability will be lost.

@thaynos
Copy link

thaynos commented May 31, 2021

does anyone know why theyre against auto-save? also do you have a ss of the argument thread XD

@thaynos
Copy link

thaynos commented Jun 1, 2021

where is the autosaved folder?

@crogonint
Copy link

Better, I can link you to the thread right here:

https://gitlab.gnome.org/GNOME/gimp/-/issues/67

@thaynos
Copy link

thaynos commented Jun 12, 2021

where is the autosaved folder?

where is it?

@thaynos
Copy link

thaynos commented Jun 12, 2021

Better, I can link you to the thread right here:

https://gitlab.gnome.org/GNOME/gimp/-/issues/67

lmao i read the thread idky maybe theyre scared of adding new features until its perfected like apple.

@Skulptron
Copy link

Skulptron commented Jun 13, 2021

TEMP FOLDER for Windows 10
From the Start menu, open the Run dialog box or you can press the "Window + R" key to open the RUN window.
Type "%temp%" and click on the OK button.

In my case TEMP folder location:
C:\Users\username\AppData\Roaming\GIMP\2.10\tmp
...

Every 10 minutes (backupInterval = 10 * 60) the script saves backups of all opened images to a TEMP folder.
The backup files won't be deleted when GIMP exits, so some manual clean-up will be required from time to time.
...
How to add .py script to Gimp:
Gimp > Preferences > Folder > Plug-ins
Select > C:\Users\username\AppData\Local\Programs\GIMP 2\lib\gimp\2.0\plug-ins
Click icon "Show file location in the file manager" .
Paste gimp-autosave.py in that folder.
Close Gimp

Open Gimp
Menu > File > Activate Autosave (activate only once)
...

Script works for me.
GIMP 2.10.24 (revision 2)
Windows 10

@thaynos
Copy link

thaynos commented Jun 13, 2021

is there any way to make the autosave feature happen more frequently?
just curious i stopped using gimp after getting tired of crashes.
i just use a portable version of photoshop now. much better ui imo.

@Skulptron
Copy link

is there any way to make the autosave feature happen more frequently?

Edit gimp-autosave.py with Notepad or VSCode and replace 10 with prefered number...
backupInterval = 10 * 60 to backupInterval = 5 * 60
But... Real question is why your Gimp crashes so often?

@thaynos
Copy link

thaynos commented Jun 13, 2021

my slow ass pc is the only reason i can think of.
i7 5500u
8gb ram
gt 840m
dont be fooled by the i7 and gt. look up their specs. id prefer a i3 over this laptop.

@horse14t
Copy link

horse14t commented Jul 13, 2023

This claims to work for 2.8 but I haven't been able to get it to show up after installing... Help?

@rairay91
Copy link

plugin not working on linux, i mean activate auto save option not showing even after installed in system as well as in home path.

@rairay91
Copy link

plugin not working on linux, i mean activate auto save option not showing even after installed in system as well as in home path.

And also as much as i know only windows detect directories in %temp% way, linux use / as directory finder (~/ for home directory)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment