Imagemagick text3/25/2023 ![]() Regarding the installation of these tools I recommend you install Python using your distribution’s package manager on Linux, using HomeBrew on Mac or by downloading the latest version of Python for Windows and to follow the installation instructions for ImageMagick and Wand on Wand’s website. More specifically, we’re going to use the Wand package from PyPI that provides an easy-to-use interface to the ImageMagick libraries. In addition to that, we’re still going to need ImageMagick, but we’re not going to use the convert CLI command because we have some nicer interfaces we can work with to build our tool since we’re running Python. The obvious requirement is Python 3 along with the PyPI pip CLI tool installed and accessible from your terminal or command prompt. What You Need to Have on Your Computerįirst of all, let’s start by outlining the required tools. ![]() What I will suppose, though, is that you have some basic knowledge of the structure of code written in an object-oriented high-level programming language (selection, iteration, classes, objects, functions, libraries, etc.). This post doesn’t suppose you have any experience with Python programming but is not intended to be a comprehensive Python introduction (there is plenty of material on that online, no need to be redundant here). The main usability improvement will be the ability to specify the input directory and output directory when running the command instead of having them depend on fixed relative paths from the working directory (. As I mentioned in that post, I was already planning to have an article guiding through the creation of a full-blown CLI utility using Python, but we’re probably better off starting with something simpler and more similar to the original script, but that solves some of the issues that are related to the language, such as the ones I described above in addition to being slightly faster and having code that’s a lot easier to read and understand (it’s so nice to use proper programming languages). Some of you in response to that post mentioned Python as an alternative. The Bash solution had multiple issues: it wasn’t portable given that it runs on a specific shell and interpreter that aren’t really great to use if you’re not using an OS that supports it natively (for example, Windows support isn’t great) and that it only works for a very specific directory structure with no files in the directory tree that aren’t images in a subfolder of a subfolder of the current directory. What the Bash Solution Was Missing: Why Move to Python The output will be in another directory, called italy_pics_organized, to be created inside italy_pics’s parent directory if it doesn’t exist there already.Īs I already said, that post outlined the process of writing a solution for this problem using Bash and ImageMagick’s convert CLI tool, but this post is here to go beyond that and write something much better with Python. With each of the subfolders ( Rome_Lazio, Florence, Sicily, etc.) containing one or more pictures. We have a directory tree that looks like this: italy_pics/ ![]() To do that, they all need to be in one folder so that they can be shown in sequence easily but they also need to be recognizable both for their filename and for some text shown on them so that the tourist doesn’t necessarily have to remember where each picture was taken. The issue was the organization of pictures from the collection of a tourist who, upon coming back from a trip to Italy, is eager to show to friends and relatives the pictures taken of the many great sights Italy has to offer. In the previous post I imagined a problem someone could have that could be really easily solved by using computers for what they’re best at: performing repetitive, predictable tasks fast and without requiring the user to do anything while the software does what it’s designed to do. TL DR of The Previous Post: The Problem We’re Going to Solve If you can’t be bothered to read that, here’s a summary. I recommend you look at that first because I explain the specific problem being solved, the directory structure and offer a simple solution to the problem. In the previous post we saw how to use Bash to build a simple script that copies some pictures organized into subfolders into a single folder while renaming them and adding some text on them to make it possible for you to know where it was taken based on the folder the pictures were in. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |