Using command line to find image of a certain size

Just a quick post of a solution to a problem I was faced with today…

So I have a directory with about 8,000 images in it and I needed to find an image that was 280 pixels in width.  How to find the images using the command line?

Well here is what I came up with:

for f in *.jpg;do if [ `identify $f | cut -f3 -d\ | cut -f1 -dx` -eq 280 ] ; then echo $f;fi;done

Works nice..  There are other versions of this out there, but they work on PNG’s not JPEG’s because the “file” commend does not return the size of a JPEG.

# file somefile.png
somefile.png: PNG image, 755 x 70, 8-bit/color RGB, non-interlaced
# file somefile.jpg
somefile.jpg: JPEG image data, JFIF standard 1.01

Bummer; but “identify” does return size data, cool..

# identify somefile.jpg
somefile.jpg JPEG 80x100 80x100+0+0 8-bit DirectClass 2.64KiB 0.000u 0:00.000

Cut the output and check for the matching size.. easy!

Carambola i2c IO board with relays – V1.1

I’ve been working on a new version of my Carambola IO board.  I’ve added an interrupt line from the MCP23017 back to the Carambola to allow for a trigger when an input changes (save on having to poll the MCP23017 to check for changes!).

One other small change was the addition of a decouple cap close to the pin headers for the Carambola module.  It helps to keep the +5V in order, on the first version there was a lot on noise on the 5V line. You can get the new schematic here: Carambola IO Board

I re-generated the artwork, broke out the light box and development kit and got to work “spinning” a new PCB.  I’m happy with my timings for exposure and development now and seem to have a repeatable process in place.

Carambola IO board - main components placed

Carambola IO board – main components placed

The double sided PCB above took about 2 hours from PC screen to etched PCB (not drilled!). Got a good clean PCB with well defined tracks.

Carambola IO board - close up of I2C extender

Carambola IO board – close up of I2C extender

Getting the new Carambola module configured was easy.  Once connected to the network I could simple copy my Lua MQTT code from my original board over SSH.

Carambola IO board - ready for testing

Carambola IO board – ready for testing

Now I have to write some more Lua code to handle the interrupt pin and post the changes on the inputs via MQTT!

pcDuino and I2C IO board

Thought I do a quick test with my pcDuino and see if I could get the I2C relay board connected and working on it.

The pcDuino is really easy to get up and running on.. Like the Carambola it can be handy to have a FTDI cable handy to get console access.  Once the serial cable is connected you can configure the network and generally get the board set up for connection to your network.  Sparkfun have a really handy tutorial with the pin-outs, etc.

Getting Ubuntu up and running is easy, and because the pcDuino has on board flash memory, there is no need for a SD card.. kinna cool.

Connecting the I2C IO board requires 3 wires from the pcDuino, no drama, simple!

pcDuino and I2C IO boardAfter I install the i2c tools, I was able to drive the relays and monitor the inputs no problem.

pcDuino and I2C IO board from end

KiCAD Howto – Library and the text editor

I was asked by one of my blog followers about using KiCAD libraries and how to make a library and add parts to it.  So I’ve written this blog entry to help all KiCAD users.

One of the very cool things about KiCAD is all the libraries are just text files, so a good editor is all you’ll need.

On a Linux install of KiCAD the default libraries are tricky for a regular user to edit as they are all owned by root, so they are really read only (unless you want to do all that sudo stuff!).

What I have done on my system is create my own library and saved it on a shared directory on my server so any machine that I login from can see the same library.

Start your text editor and create a new library that has no parts in it, it’s just a “shell” like this:

EESchema-LIBRARY Version 2.3  Date: Wed 07 Nov 2012 01:16:37 PM GMT
#encoding utf-8
#End Library

Save this somewhere and call it something like “MyKiCADLib.lib”

Now when you start a new schematic go to “Preferences -> Library”

KiCAD: Select Library from the Preferences Menu

KiCAD: Select Library from the Preferences Menu

In the Library window:

KiCAD: Add a new library

KiCAD: Add a new library

Click on the “Add” button on the right top (near the “Component library files”) and find and select the MyKiCADLib.lib.  The press the “OK” button on the Library preferences window to finish.

Now when you add a component select the “Select by Browser” and you can search for it in your new library… It the moment this library has no parts in it, but it should show up in the left most panel.

KiCAD: New Library is empty...

KiCAD: New Library is empty…

So now it is time to add a part to the new library.  You have two options, you can go ahead and use KiCAD library editor.  This is nice, and I’ve used it a few times when I can’t find a part on the net.  But like most things on-line, someone has probably done the work already!

I’ve found that the part I’m interested in is somewhere in a existing library that may have a few hundred parts in it and I’m only looking for the one part.  So rather than adding yet another library to KiCAD I extract the part from the library and add it to my library.  As the libraries are all text this is easy to do.

For example the DS18B20 is defined like this:

# DS1820
DEF DS1820 IC 0 40 Y Y 1 F N
F0 "IC" -100 400 60 H V C CNN
F1 "DS1820" 0 300 60 H V C CNN
F2 "~" 0 0 60 H V C CNN
F3 "~" 0 0 60 H V C CNN
S 150 -100 -150 250 0 1 0 N
X GND 1 100 -400 300 U 50 50 1 1 W
X DQ 2 0 -400 300 U 50 50 1 1 W
X Vdd 3 -100 -400 300 U 50 50 1 1 W

Parts always start with a DEF and end with an ENDDEF. Look out for these if you are taking a part from an existing library.

Paste the text into you new shell library:

EESchema-LIBRARY Version 2.3  Date: Wed 07 Nov 2012 01:16:37 PM GMT
#encoding utf-8
<insert component text here>
#End Library

Save your modified library and exit out of the schematic editor and restart it (required to pick up changes to libraries!).

Now when you add a component you should see your library has two parts in it: “DS1820” and “DS18B20”.  Go ahead and add this to your schematic.

KiCAD: Part added to library

KiCAD: Part added to library

It as easy as that.. Hope you found this a help!