Giter Club home page Giter Club logo

cropall's Introduction

cropall

A small cross-platform python script to interactively crop and resize lots of images images quickly. Image editors like gimp take way too long to start, open an image, crop it, export it. A batch job/script can automate it but everything gets cropped at the same positions. This app sits in the middle, automating loading/clicking crop/save/next so your amazing human vision can be used to quickly select what needs to be cropped and not wasted on navigating clunky GUI hierarchies.

This is really a minimal GUI and preview for the following imagemagick command:

convert in.jpg -crop <region> -resize <fit> out.jpg

This script actually uses imagemagick under the hood for its fast and high quality resampling algorithms. The GUI shows a quick and low quality preview.

Controls

Select the source directory to process. By default results are written to a crops subdirectory.

  • space - crop and advance to the next image
  • left/right - previous/next image
  • click - move the selection, or drag to box-select depending on the mode (hold shift to move the box-select)
  • scroll - adjust crop size when using scroll mode (hold shift for small adjustments)

gui preview

Buttons:

  • Copy - copy the source image file to the output directory (no crop/resize)
  • Resize - shrink the image to the smaller of the given width or height, keeping aspect ratio
  • Crop - crop the image to match the region shown in the preview, also resizing if the option is selected

Install

Download a pre-built from the releases section on github. These are self contained packages created with pyinstaller.

Alternatively, grab the source and dependencies. I hope it's simple enough that people with a little python experience can adapt it as needed.

git clone https://github.com/pknowles/cropall.git
cd cropall
python -m venv .venv

# linux
. .venv/bin/activate

# windows
. .venv/Scripts/Activate

pip install -r requirements.txt
python cropall.py

# Install ImageMagick https://docs.wand-py.org/en/latest/guide/install.html
# E.g.:

# Ubuntu
sudo apt-get install libmagickwand-dev

# Fedora
sudo dnf install ImageMagick-devel

# Windows (make sure to match python x86 or x64)
# Download dll from: https://imagemagick.org/script/download.php#windows

# Optional: create the standalone binary distribution
pyinstaller cropall.spec

Feel free to report issues and post ideas. Pull requests are most welcome, thank you! I can't promise I'll get to them immediately but I'm grateful for your time to improve the app ๐Ÿ˜Š.

Forks and alternatives

License

The python source code here is under GPL v3.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Third party code

Pre-built binaries of ImageMagick are included with the distribution. See: https://imagemagick.org/script/license.php

The release distribution includes various scripts and binaries collected by pyinstaller. Licenses found in the venv directory are included by cropall.spec.

cropall's People

Contributors

happytetrahedron avatar maxgyver83 avatar pknowles avatar superstar54 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cropall's Issues

Installation on Ubuntu 14.10

Hi, I am about to test the cropall.py script on Ubuntu 14.10.

For your information, here is what I had to do to get it running:

  • Cloned with git clone https://github.com/pknowles/cropall.git
  • Changed shebang of cropall.py from #!/bin/python to #! /usr/bin/env python2
  • installed python-tk : sudo apt-get install python-tk
  • installed python-imaging-tk : sudo apt-get install python-imaging-tk
  • run script from terminal window with ./cropall.py

Maybe this info should be added to README.md ?

Do not overwrite crops

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!

On custom aspect ratio the preview distorts

Hi. I've changed the line 422 like that:

preview = ImageOps.expand(preview, border=((bbox[2]-preview.size[0])//2, (bbox[3]-preview.size[1])//2))

to avoid that distortion.

Very helpful script.
Thank you very much!

Crop button not there

Can be solved by replacing line 248 with

self.inputs[-1].grid(row=0, column=9, sticky="nsew")

Add some way to configure the output path and filename

It'd be nice to have some way to configure the the output filename (currently it's hidden in the .ini config and it's only an output path). Maybe something like a textbox that can take a format string, e.g. crops/{original}_cropped_{datetime}.{ext}?

Crop allowing different aspect ratio

Perhaps aspect ratio is the wrong word, if I drag a square over a range of 100x123 pixels that the image I want to save. After making that square I'd like to drag the handles of it to make more minor adjustments, also using the arrow keys for minor pixel adjustments would be great.

Error: no resize specified. Not resizing

The error can be avoided by replacing line 392

c += " -resize \"" + str(resize_width) + "x" + str(resize_height) + ">\""

against

		if (resize_width > 0):
			c += " -resize \"" + str(resize_width) + "x" + str(resize_height) + ">\""
		c += " \"" + os.path.join(self.outDir, self.currentName) + "\""

Fork specifically for book scanning

I just wanted to let you know that I made a fork of your code, and modified it to accommodate cropping scans of books. I feel like it does not have a place in your repo because you wrote this specifically for a different kind of workflow but feel free to pull in my changes.

The following changes have been done:

  • Changed the bounding box from yellow to red
  • A much more granular "zooming" factor
  • Key-bindings for arrow keys, and ctrl+arrow keys
  • key binding for rotating
  • deskewing before cropping

Thank you for sharing your work. I found your repo from your answer in this question: http://askubuntu.com/questions/97695/is-there-a-lightweight-tool-to-crop-images-quickly

PS. That person that commented on your answer was a bit of an a**.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.