Tag: Linux

Image Processing with GIMP Batch Mode on the Command Line

BAM! Another reason I love Linux and free and open source software. 

My phone becomes an invaluable tool when I begin working on a project, namely for its camera. I have an elaborate system set up where I snap photos, they save to my phone as well as upload to my cloud when I’m connected to WiFi. Once my task is done for the project and the files have automatically found their way to my server, I sort and catalogue the files into specific project folders. Sometimes, these folders full of photos need to make their way to this website.

On my LG, the camera is spectacular, so I don’t hesitate to use it to its full potential. Each photo can be upwards of 10 MB though, which doesn’t make for fast web browsing, especially if one is simply browsing on their tablet or phone. If someone’s browsing on their desktop, chances are their monitor is running 1920 x 1080 resolution, so the native 5312 x 2988 resolution my LG produces actually serves against me.

I use GIMP for all my simple manipulation of photos and images. It’s easy to open up a file and scale the resolution… but it becomes very, very time consuming and mind-numbing when it comes to manipulating a hundred or so photos. And that’s where the little known Batch Mode that’s built into it helps me big time in taking care of what should be a simple task. I just want to take a bunch of photos and make them all 1080p!

Here’s how I went about doing it.

Firstly, I visited GIMP’s webpage which does a basic job of introducing the capabilities and where to find the information one needs to use it.

Then I perused their example of processing several files, admiring what looked to be some LISP functions and formatting I’m familiar with from my old AutoCAD LISP programming days.

I had no interest in applying an Unsharp Mask filter to the photos, as shown in the example, but I was interested in the “gimp-image-scale” procedure found in the Procedure Browser found under the Help menu. All I had to do was figure out how to use the parts of the example I was interested in, do away with what I don’t want, and insert what I do want.

To cut to the chase though, here’s the script that will need to be saved to your ~/.gimp-2.8/scripts directory (being mindful of the version number, of course):

(define (batch-resize-to-1080 pattern)
 (let* ((filelist (cadr (file-glob pattern 1))))
   (while (not (null? filelist))
          (let* ((filename (car filelist))
                 (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
                 (drawable (car (gimp-image-get-active-layer image))))
            (gimp-image-scale image 1920 1080)
            (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
            (gimp-image-delete image))
           (set! filelist (cdr filelist)))))

Copy it, paste it into a text file, name it whatever you want. Just ensure it’s in GIMP’s script directory and it has the .scm file extension. Then in your terminal, navigate to the directory where you have copied your photos to manipulate (this script will overwrite your original files), and type out the following command:

gimp -i -b '(batch-resize-to-1080 "*.jpg")' -b '(gimp-quit 0)'

I’m not going to dig into how to interpret LISP (Lost In Silly Parenthesis), but I’ll try to dumb things down in a way that would allow the initiating scripter to take this example or GIMP’s example and understand what they can tweak and what they can’t tweak.

If it’s not immediately clear, it needs to be pointed out that all the 10 lines of code are called by that 1 line of code using “batch-resize-to-1080”. In the 10 lines of code, we’re essentially defining our own command that we can use within GIMP. So name this whatever you’d like, but just ensure it matches between the script and the command.

A big difference between this example and GIMP’s example, is the number of parameters/variables/arguments required to run the custom script. If you look back at GIMP’s example, you’ll see you have to type out the name of the custom script and then you have to specify a file extension, and a series of numbers. If it’s unclear why these need to be typed in, be sure to review “plug-in-unsharp-mask” in the Procedure Browser. These parameters are required to be entered on the command line so that this procedure can be used. But because I’m not interested in using this procedure, and I’m interested in using “gimp-image-scale” instead, I can leave out the “radius”, “amount”, and “threshold” parameters. 

The little difference between this example and GIMP’s example, is the one line in the rest of the script that gets replaced. Instead of:

(plug-in-unsharp-mask RUN-NONINTERACTIVE image drawable radius amount threshold)

I simply want:

(gimp-image-scale image 1920 1080)

Now, if you wanted the ability to define the pixel width and height at the command line, you’d want to add the variable names here on this line as well as back up in that first line of the script where you define the procedure name and its parameters. For my purposes though, I know this is the resolution I want and I likely won’t have to change it, and I like the idea of typing less to run the script.

And that’s essentially it; just know the example may look intimidating with all the parenthesis and indents and such, but when it comes down to making a script of your own, know what little you have to change.

In my case, it was less than I thought I’d actually have to change. I wanted to batch convert all the images to 1920 x 1080 resolution, but given the fact that some photos are taken in portrait and others in landscape, I thought I’d have to gather this information within each file and enumerate the width and height based on its orientation. I’m glad I tested early! GIMP actually manages this automatically and no further scripting effort was required on my part.

To sum it up… figure out the name of the procedure(s) you want to use automatically across multiple files, determine the parameters those procedures require using the Procedure Browser, identify the little differences I noted above and modify them to suit your needs.

If all’s good, you’ll see “batch command executed successfully” in the terminal.

Before I Say CAD, Let Me Just Say This

Continuing on from CAD Applications on Linux:

Before I chime in on what I think would make a CAD application successful on Linux… perhaps I should back it up. I’d like to clear the air on what it is I’m talking about when I say “CAD”. I believe this is the most important definition for the Linux community to grasp hold of and understand clearly.

CAD stands for Computer-Aided Design or Computer-Aided Design and Drafting (CADD), and CAD software uses computer technology to create, assist and manage a design and its documentation.

An easy question to ask yourself, if you’re wondering whether or not CAD software is required, is, “Am I creating something?” Typically, if something’s being created, it will be subject to a level of designing. And if something is to be designed, it’s likely to change. And it’s precisely the changing, which calls for the use of computer technology. Computers can manage the change of a design much more efficiently than we humans can, but for computer technology to efficiently aid us, we must consider the kind of designing we’re performing. After all, someone has to tell the computer what to do. How you design a road isn’t the same as designing a bridge. Designing a house isn’t the same as designing an automobile. It’s these differences in the type of designing we do which brings us an overwhelming amount of software applications divided by industry and tasks, targeted for specific design methods.

If categorizing CAD software by tasks, we’d recognize 2D vector (or drafting) applications, 3D modelling applications, animation applications, analysis, GIS server software, etc. If categorizing CAD software by industry, we’d recognize the architectural, engineering, construction and manufacturing industries, among others. And if you take the manufacturing industry alone, think of all the different things that could be manufactured and the specialized software that may exist because of the differences between these things. Further, not all software is tuned for just one industry or one task. Often, many tasks are utilized within an industry, or many industries rely on one or two specific tasks.

This plethora of “CAD” can be a good thing as well as a bad thing. The Good? CAD technology can be harnessed and tuned to do so many different things; affording us a quick way to build something, a way to communicate a complicated design, a way to determine whether or not something is safe or a way of proving that an idea will work in the real world, and of course managing how these ideas change along the way. The Bad?

Semantics.

People have been known to bastardize the acronym in ways such as, “I need someone to CAD this up.” or “Yeah, I do CAD.” We’re placing too much meaning on the acronym and it’s leading to too much confusion. And rightfully so! It’s easier to say “CAD” than it is to describe what finite element analysis is in the context of parametric solid modelling in the manufacturing industry. It’s easier to say “CAD” than it is to describe what grading is in the context of pattern making for the fashion industry. It’s easier to say “CAD” than it is to describe a graphics pipeline in the context of rendering for the animation industry. And really, by saying “CAD”, it is actually describing these things correctly; just very generally.

So… not so much a problem with the technology itself; more to do with humans, right?

Right. We all have this little switch in our head that flicks off the moment we become disinterested in the information we’re receiving, and it causes our ears to work less with our mind. (Here’s where I thank you if you’re still following me.) So I’ve learned that I have to tune the way I communicate what I do to the ears that are listening. The way I describe what I do to my mother isn’t going to sound the same as how I describe my craft in a job interview. And on the flip side, from an interviewer’s point of view; just because I may be an expert in 2D drafting, doesn’t necessarily mean I’d be hired as a Render Wrangler, but both applicants may be CAD Technologists.

In other words, a certain type of attention needs to be paid to the way CAD is communicated because it’s capable of being received in so many different ways; its capable of meaning so many different things. I believe the same level of attention needs to be paid within the Linux community.

What’s the context?
What is being performed?
For who?

The more effort placed in communicating precisely what form of CAD technology is being done, the greater chance there is for the Linux community to do what they do best, hopefully leading to a true suite of CAD software available on Linux.

Installing Bitwig on the openSUSE Linux Distribution

I’ve been successfully running Bitwig on openSUSE for about a year now. I have been able to successfully install upgrades for Bitwig, and have even switched from openSUSE 13.2 to openSUSE Tumbleweed successfully. Frankly, I am downright amazed by the fact that this is all working.

Bitwig is arguably a game-changer as far as digital audio workstation (DAW) software goes, and impressively, it’s available for Linux. Ubuntu Linux, that is.

So… if it is only released for the Debian-based Ubuntu Linux distribution… how was I able to install it on the RPM-based openSUSE Linux distribution?

Meet Joey Hess, and figure out how to buy him a beer. He authored the Perl script called alien which converts software packages (like a .deb package to an .rpm package!). Following me? Ensure it’s installed on your machine.

Head to Bitwig’s website and download the demo for the Ubuntu platform.

Open up your terminal and get cracking!

Switch to the root user and enter your password:

su

Run the following to convert the Debian-based software package to an RPM-based software package which openSUSE can work with:

alien -r bitwig-studio-1.x.x.deb

Depending on your machine, it may take a while. Perhaps look up Brian Bollman in the mean time. He offers a plethora of video tutorials which will get you up to speed with Bitwig quickly and confidently, regardless of your experience with digital audio workstations or audio in general.

When alien is done, you’ll see something like:

bitwig-studio-1.x.x-x.x86_64.rpm generated 

With the .rpm generated, we can check the dependencies of the package by running the following:

rpm -i --test bitwig-studio-1.x.x-x.x86_64.rpm

Now, the following is going to depend on what you already have installed on your machine. The machine I am testing on is set up in a fairly bare-bones manner, so I anticipate that the majority of people will experience the same:

error: Failed dependencies:
    libavcodec.so.53()(64bit) is needed by bitwig-studio-1.x.x-x.x86_64
    libavcodec.so.53(LIBAVCODEC_53)(64bit) is needed by bitwig-studio-1.x.x-x.x86_64
    libavcodec.so.54()(64bit) is needed by bitwig-studio-1.x.x-x.x86_64
    libavcodec.so.54(LIBAVCODEC_54)(64bit) is needed by bitwig-studio-1.x.x-x.x86_64
    libavformat.so.53()(64bit) is needed by bitwig-studio-1.x.x-x.x86_64
    libavformat.so.53(LIBAVFORMAT_53)(64bit) is needed by bitwig-studio-1.x.x-x.x86_64
    libavformat.so.54()(64bit) is needed by bitwig-studio-1.x.x-x.x86_64
    libavformat.so.54(LIBAVFORMAT_54)(64bit) is needed by bitwig-studio-1.x.x-x.x86_64
    libbsd.so.0()(64bit) is needed by bitwig-studio-1.x.x-x.x86_64
    libbsd.so.0(LIBBSD_0.2)(64bit) is needed by bitwig-studio-1.x.x-x.x86_64

This essentially means… for the Bitwig .rpm to install and work correctly, it’s going to depend on the above packages. So, open your YaST and look up these packages. Try searching for libavcodec, libavformat and libbsd. It’s been confirmed that they aren’t there, but maybe you’ll learn something in the process of searching.

Here’s what I found:

screenshot-from-2016-11-22-19-56-36

screenshot-from-2016-11-22-19-58-03

screenshot-from-2016-11-22-19-59-08

With a few basic searches, I learn that libavcodec and libavformat are part of the FFmpeg library, and it looks like openSUSE has a few libavcodec and libavformat packages installed, though not the same ones that Ubuntu uses which Bitwig expects. Another thing I notice is that the failed dependency error we received earlier didn’t explicitly name the package as we’d expect to see in YaST. It looks as though where we are told we require libavcodec.so.53(), when we actually need to look for a package that is named libavcodec53. Lastly, it looks like the libbsd0 package is available in our standard openSUSE repositories, so taking care of this dependency is as easy as checking the box and installing. So go ahead and do that while YaST is open… or close YaST and be explicit in your terminal:

zypper install libbsd0

Now, because I’m not interested in hosting Linux packages, and neither do I want to encourage people to blindly download and install packages from a source they’re not 100% familiar with (including my website), this is where I tell you to spread your wings and fly. Your homework is to find the libavcodec53, libavcodec54, libavformat53 and libavformat54 packages and ensure they are manually and properly installed on your machine.

After completing your homework, run:

rpm -i bitwig-studio-1.x.x-x.x86_64.rpm

And revel in the typing of your final command:

bitwig-studio

Voila!! Bitwig will load, step you through the EULA and prompt you to install any content packages, if you’re interested.

screenshot-from-2016-11-22-21-11-48

Did you experience problems finding and installing the libavcodec53, libavcodec54, libavformat53 and libavformat54 packages? No biggie. As a last resort, you could simply forget about ’em and force Bitwig to install anyways… Not recommended, but on a test machine I was able to successfully run Bitwig even without these dependencies. There are likely to be features of Bitwig which fail to work, but I wasn’t able to find them.

Run the following:

rpm -Uvh bitwig-studio-1.x.x-x.x86_64.rpm --nodeps

Then:

bitwig-studio

Merry beat-making!!

CAD Applications on Linux

I’m relatively new to Linux. My first experience with Linux was configuring a dual-boot setup with Windows XP and Ubuntu back in 2008. Dissatisfied with what Ubuntu and Linux had to offer then, I attempted again in early 2011. Again, I was dissatisfied. Round three, I’m surrounded by all things Linux. I have a Synology NAS, Nexus 5, Nexus 7, LG G4, my Ultrabook running only openSUSE and my desktop dual-booting openSUSE and Windows 10. Am I, now, still dissatisfied?

Well… that leads to a complicated answer…

I would first need to explain where I was dissatisfied back in 2008. It was a pretty significant year for me, considering my main jam: AutoCAD. I had transitioned my way through AutoLISP and gained traction with AutoVBA programming and had began to peruse the ObjectARX SDK. AutoCAD had a foothold on dynamic blocks for a couple years, and had just introduced annotative objects and data extraction. These were big milestones for Autodesk and it positively impacted my work. And in my opinion, AutoCAD still had its own degree of identity… this was before it had adopted Microsoft’s ribbon user interface. Among all this geeky reminiscing… what I’m trying to express is that if I had any interest or investment in computer technology… it was in the realm of computer-aided design technology.

Actually… it still is, and that’s what makes this Linux satisfaction answer so complicated, because at the time, I couldn’t utilize the same CAD technology I was used to, yet there was a sense of freedom in using Linux.

I am very satisfied witnessing Linux evolve into what it is now, since 2008. Though, I remain dissatisfied to see that CAD applications haven’t evolved much. And it’s this reason why I maintain my desktop workstation with Windows 10; simply to utilize Autodesk software. But even admitting that I continue to run Windows 10 just for Autodesk software causes me to feel shame.

In my 8 years experimenting and familiarizing myself with Linux, I have become more familiar with the kernel concept and the different types of software licenses, and have consequently grown a huge respect and admiration for free and open source software. Throughout the same time, I have witnessed Autodesk products, AutoCAD specifically, evolve in parallel with Microsoft and increasingly bloat their software to a point where it seems adverse to what made AutoCAD so valuable in the first place. Really… what am I holding onto? In principle, I would rather uphold free and open source software. And in logic, I believe the more highly cohesive and loosely coupled software to be more efficient, valuable and functional. So specifically… why am I holding onto Autodesk products?

You could say, perhaps, it’s because my education and experience revolves almost entirely around Autodesk products. I certainly wouldn’t be where I am today if it weren’t for Autodesk doing what they’re doing and me following suit. You could also say it’s because organizations revolve almost entirely around Autodesk products too, and this certainly shouldn’t be taken lightly.

Or you could say it’s simply because Linux CAD applications bite.

And they do.

Not exactly a great way to begin making friendships with Linux developers… I certainly don’t mean to slight anyone or discount the time and energy that’s been placed into the open source CAD applications, but I believe that the Linux community has opportunity to do so much better. I believe the community is already better, and that Autodesk is providing the community a stage, considering the direction they’re moving. I simply wish the CAD FOSS reflected it. In fact, 8 years has shown me I need free and open source CAD software.

I am willing to move away from Autodesk products. I am so close. And that statement I made above, that shouldn’t be taken lightly; I really do believe organizations too, large or small, can transition to open source software in the right conditions.

© 2018 Drew Merryman

Theme by Anders NorenUp ↑