pknowles/cropall

Do not overwrite crops

Closed this issue · 1 comments

Hi!

This program was almost excellent for me! Only thing I was missing was the option to not to rewrite cropped images (i cut scanned pages to portions of text and images).

Python is not very well known for me so I believe it can be done much better, but it's all I can do:

In "try" I added:
import time
In class MyApp(tk) I've modified getImages to make it load images sorted by name:
for i in sorted(os.listdir(dir)):
Modified binds:

		#self.bind('<space>', self.save_next)
		#self.bind('d', self.next)
		self.bind('<space>', self.next)  
		self.bind('s', self.save)        

And added complete "save" function:

	def save(self, event=None):
		box = self.getRealBox()
		filename_l, file_extension_l = os.path.splitext(self.currentName)
		currentName_l = filename_l + "-" + str(int(time.time())) + file_extension_l
		c = "convert \"" + os.path.join(self.inDir, self.currentName) + "\""
		c += " -crop " + str(box[2]-box[0]) + "x" + str(box[3]-box[1]) + "+" + str(box[0]) + "+" + str(box[1])
		if (resize_width > 0):
			c += " -resize \"" + str(resize_width) + "x" + str(resize_height) + ">\""
		c += " \"" + os.path.join(self.outDir, currentName_l) + "\""
		print c
		subprocess.Popen(c, shell=True)
		print "Running"

It adds to new file name datestamp, so nothing will be overwritten.

It might be useful for someone.

Best regards!

That's a good idea, thanks!

I had been using this with overwriting as a feature so that I could re-do a crop if I made a mistake, but I totally agree the default should be more careful abou that kind of thing.

Maybe a checkbox to allow overwriting without prompting and some way to format the output filename, e.g. a textbox with crops/{original}_cropped_{datetime}.{ext}.

[edit] created #13 to track