Posts Tagged ‘imagemagick’

My Software Stack 2011 edition

Saturday, December 31st, 2011

I realize that I haven’t written my customary “software stack” post for this year yet. But hey, from where I’m sitting, I still have … 36 minutes to spare ;)

I’ll be using the same categories as last year; system, communications, web, development, office suite, server, organization, and entertainment.

System

The OS of choice is still Archlinux, my window manager is still wmii, my terminal emulator is rxvt-unicode, upgraded by also installing urxvt-tabbedex.

My shell is still bash, my cron daemon is still fcron, and my network manager is wicd.

To this configuration I’ve added the terminal multiplexer tmux, and have lately found out just how useful mc can be. Oh, and qmv from the renameutils package is now a given part of the stack.

Communications

Not much change here, Thunderbird for email, Pidgin for instant messaging, irssi for IRC.

Heybuddy has been replaced by identicurse as my micro-blogging (identi.ca) client. Heybuddy is very nice, but I can use identicurse from the commandline, and it has vim-like bindings.

For Pidgin I use OTR to encrypt conversations. For Thunderbird I use the enigmail addon along with GnuPG.

This means that Thunderbird still hasn’t been replaced by the “mutt-stack” (mutt, msmtp, offlineimap and mairix) and this is mostly due to me not having the energy to learn how to configure mutt.

I also considered trying to replace Pidgin with irssi and bitlbee but Pidgin + OTR works so well, and I have no idea about how well OTR works with bitlbee/irssi (well, actually, I’ve found irssi + OTR to be flaky at best.

Web

Not much changed here either, Firefox dominates, and I haven’t looked further into uzbl although that is still on the TODO list, for some day.

I do some times also use w3m, elinks, wget, curl and perl-libwww.

My Firefox is customized with NoScript, RequestPolicy, some other stuff, and Pentadactyl.

Privoxy is nowadays also part of the loadout, to filter out ads and other undesirable web “resources”.

Development

In this category there has actually been some changes:

  • gvim has been completely dropped
  • eclipse has been dropped, using vim instead
  • mercurial has been replaced by git

Thanks in no small part to my job, I have gotten more intimate knowledge of awk and expect, as well as beginning to learn Perl.

I still do some Python hacking, a whole lot of shell scripting, and for many of these hacks, SQLite is a faithful companion.

Doh! I completely forgot that I’ve been dabbling around with Erlang as well, and that mscgen has been immensely helpful in helping me visualize communication paths between various modules.

“Office suite”

I still use LaTeX for PDF creation (sorry hook, still haven’t gotten around to checking out ConTeXt), I haven’t really used sc at all, it was just too hard to learn the controls, and I had too few spreadsheets in need of creating. I use qalculate almost on a weekly basis, but for shell scripts I’ve started using bc instead.

A potential replacement for sc could be teapot, but again, I usually don’t create spreadsheets…

Server

Since I’ve dropped mercurial, and since the mercurial-server package suddenly stopped working after a system update, I couldn’t be bothered to fix it, and it is now dropped.

screen and irssi is of course always a winning combination.

nginx and uwsgi has not been used to any extent, I haven’t tried setting up a VPN service, but I have a couple of ideas for the coming year (mumble, some VPN service, some nginx + Python/Perl thingies, bitlbee) and maybe replace the Ubuntu installation with Debian.

Organization

I still use both vimwiki and vim outliner, and my Important Dates Notifier script.

Still no TaskJuggler, and I haven’t gotten much use out of abook.

remind has completely replaced when, while I haven’t gotten any use what so ever out of wyrd.

Entertainment

For consuming stuff I use evince (PDF), mplayer (video), while for music, moc has had to step down from the throne, to leave place for mpd and ncmpcpp.

eog along with gthumb (replacing geeqie) handles viewing images.

For manipulation/creation needs I use LaTeX, or possibly Scribus, ffmpeg, audacity, imagemagick, inkscape, and gimp.

Bonus: Security

I thought I’d add another category, security, since I finally have something worthwhile to report here.

I’ve begun encrypting selected parts of my hard drive (mostly my email directory) using EncFS, and I use my passtore script for password management.

And sometimes (this was mostly relevant for when debugging passtore after having begun actively using it) when I have a sensitive file which I for a session need to store on the hard drive, in clear text, I use quixand to create an encrypted directory with a session key only stored in RAM. So once the session has ended, there is little chance of retrieving the key and decrypting the encrypted directory.

Ending notes

That’s about it. Some new stuff, mostly old stuff, only a few things getting kicked off the list. My stack is pretty stable for now. I wonder what cool stuff I will find in 2012 :D

:wq

2011w34

Sunday, August 28th, 2011

Imagemagick, again

There has been quite a lot of hacking using imagemagick this past week, all of it for FSCONS use.

My first hack was to create an image for use in the MyConf site, to visually mark up passed timeslots as, well… passed.

The idea I had was to set a background on that html element which would have “Session has ended” written diagonally from the lower left corner to the upper right.

Greg convinced me that there must be better ways to mark this up which would at the same time not interfer with the readability of those sessions, and we ended up going another way, but this is how to create images with diagonal text anyway:

$ convert -size 400x200 xc:none -fill red -pointsize 40 -gravity center -draw "rotate 337.5 text 0,0 'Session has ended'" tmp.png

This will create a 400px wide by 200px high image, with a transparent background and red text, rotated to lay diagonally across the image, beginning in the southwest corner of the image and ending in the northeast.

The next day Rikard had an idea about using an FSCONS crowd image as background for another image, and have parts of the crowd “bleed through” the overlaying image.

This is of course something one can do in GIMP, iff you have learned how to. Rikard struggled with that, got help from Jonas, but ultimately the result wasn’t good, and he’d have to do it all over again, at which point Jonas had left for the day and he didn’t remember what had been done.

Which got me thinking “this must be doable in imagemagick, and repeatable (i.e. a shell script)”. Of course it was.

It is a two-step process, first you’ll need to prepare the overlaying image, by making parts of it transparent, enabling the background image to bleed through. This is done with:

$ convert overlaying-image.png -transparent black new-image.png

In the above example, the color black in “overlaying-image.png” will be made transparent, and the output saved into “new-image.png”.

For my tests, as I only needed a background image, and as anything would suffice, I had imagemagick create one for me:

$ convert -size 525x525 xc:blue bg.png

This will create an 525*525 pixel image with a blue background color.

With this done, all we need do is to merge the two images (“new-image.png” and “background-image.png”) together:

$ composite -gravity center new-image.png background-image.png resulting-image.png

One little gotcha with this command above: I haven’t tried what happens when I use two differently sized images. I am assuming that things will get cropped.

Media Queries

This Thursday I was introduced to Media Queries, a rather cool technique for having CSS determine (well, I suppose it really is the web browser which does all the work, while CSS is just the container for the rules) which styles to apply, depending on certain browser attributes (such as current width of the window, etc.)

Greg has implemented this in MyConf and it is pretty cool when you shrink your browser window down to about 200 pixels or so, and the page transforms before your eyes.

graphvis and neato

On thing which have bothered me about neato for a long time is that I could never find a way to have the nodes not overlap in the generated image.

There is syntax for how to space out nodes inside the graphviz grammar, and it works… sortof, but I actually found a better way to go about it now.

$ neato -Tpng -o resulting-file.png -Goverlap=false graph.dot

WordPress

When I updated the WP Stats plugin this Friday I was “greeted” with the message that I wouldn’t receive any further updates to the stats plugin and that I should get Jetpack instead.

It promised to be great and awesome and connect my blog to the “WP cloud” (whatever that is), but instead of filling me with optimism and making me look forward to that change, all that message managed to do was make me think “ok, I wonder how long before they’re gonna start charging for access to all this Jetpack functionality”.

Automattic is of course free to do so if they feel like it, but I can’t help but feel that it is ass-backwards to have the self-hosted wordpress.org platform, and then try to tie it into that “WP cloud” (whatever that is, again they leave me with more questions than answers)…

The funny thing is that WP Stats was one of the features that I really liked, and which made me hesitant to move somewhere else.

So thanks Automattic… but no thanks. Time to speed up the plans for migrating to fugitive…

2011w30

Sunday, July 31st, 2011

Hacking the shell

I’ve scratched some itches this week, some by pure luck, others by seeking these itches out and scratching them with a vengeance ;)

Added to my ~/.bash_aliases is now alias pwd='pwd -P' which tells pwd to resolve the real path when you have cd’d in to a symlinked directory.

Not really a hack, but I discovered Meta-BackSpc / ESC-BackSpc which will, unlike Ctrl-w, delete parts of a path, instead of the entire path.

This thread was of great help in finding that key combination.

Also, thanks to Rikard I got hold of this document which outlines how I would go about getting a word, after the cursor, deleted. Before the cursor is eash (Ctrl-w), but after has always eluded me. Turns out it is Meta-d (or, as in my case, if that is overridden by your window manager, “ESC d”). VERY nice!

I did update my PS1 variable, both for root and my ordinary user. I don’t really know why I hadn’t thought of adding a time indicator before.

There have been times when I have started a long running process, and half an hour or so into it realized that it would have been nice to time the process. Now, this wouldn’t exactly be able to fully replace time, but could do in a pinch so to speak.

root: PS1='\n\[\e[0;33m\][\t] \[\e[0;31;5m\]\u@\h\e[25m\] \[\e[01;34m\]$(pwd)\n\[\e[0m\]# '

which will create the prompt:

[HH:MM:SS] root@host /present/working/directory
#

(yes, root@host IS blinking. root can haz be seriuz bizness!)

user: PS1='\n\[\e[0;33m\][\t] \[\e[0;37m\]\u@\h \[\e[01;34m\]$(pwd)\[\e[0m\]\n\$ '

and this produces

[HH:MM:SS] patrik@host /present/working/directory
$

ImageMagick and Animations

I kindof just assumed imagemagick would have some sort of way of creating an animated gif, and of course imagemagick didn’t let me down.

What surprised me was how incredibly easy it was.

Duck Duck Go (as I am attempting a google-free week) gave me this result, and once I had tweaked the parameters somewhat I ended up with this: $ convert -delay 50 -loop 0 root*.gif rootshell.gif

Zenity and passtore

I also managed to convince (nagged him until his ears risked falling off ;)) Rikard to try out my password management system passtore.

He did have one counter-demand however: he’d need a GUI for day-to-day operations. Me, being a wmii acolyte, can do without it, but I can see how he would feel different, and seeing as it would be a fun exercise, and I’d get him to give it a shot, I sat down and had at it.

Zenity was my first thought, and as it worked out well, it was my only thought ;) The working name for that code is “Heaven ZENt”. Yes I know, I am a stupid wanker, I can live with that ;D

I am however pondering whether I should release this code as a separate project (it depends on passtore, and is useless without it, which should indicate “no”) or not (it does introduce a dependency on zenity, which isn’t strictly needed to operate passtore).

At present time it is only a wrapper around the getpass script from passtore. In essence, “heaven ZENt” is “wyrd” to “passtore’s” “remind”. I am unsure as how to proceed. Input would, as always, be appreciated.

Musings

I’ve given myself the mission to move one of my (spam-trap) email accounts from Thunderbird to mutt. I really want to be able to use mutt as that would be one less thing I’d need to start X for.

So I am looking at other peoples .muttrc files, and came across the index_format setting. This controls how your list of emails in an “inbox” is presented. In Thunderbird this view (simplified) is “some flags, subject, some more flags, author name, even more flags, date”, and what I realize from the .muttrc files I’m viewing, is that at least some people place the date before author, before subject.

That got me thinking about whether this is some sort of brain hack, to force the brain into working in a different way. Coming from Thunderbird, when a new message arrives in a conversation my reaction is to either open it, or let it be for now, depending on whether it is a discussion I am interested in.

At that point I don’t bother to look at the author field, if the conversation is uninteresting (to me) I will simply defer it to later, and if it is interesting I will simply open the new mail and read it, thereby getting to know who wrote it.

Putting the author in front of the subject could let you filter on people rather than on subject, as we all have some people we listen more intently to than others, so whatever discussion they’re in, it might be worth while to read it.

But that still didn’t explain why they’d put date and time before author. The only idea I have about this is that some mails will be urgent and thus it is good to see when they arrived. But I don’t know. I think I will try out “flags, author, subject, datetime” and see how that goes.

Revelation

If you mess up the datetime settings in BIOS (because you have powered down and unplugged your system during a thunderstorm, AND your motherboard is so old that the CMOS battery is dead) you may experience some problems when booting.

In my particular case, FSCK (or whatever binary it is that is performing a quick check on the file system during boot) reported that the datetime was now 2011-07-11 (because I fucked that up), but the last check had been performed in 2011-07-22.

This made it confused and prompted me to manually repair the file system, by entering the root password (which I have unset, -1 for sudo / me) and doing some operations.

That was actually not such a fun night trying to get to the bottom of that.

:wq

2011w27

Sunday, July 10th, 2011

Imagemagick hackery

This post outlines how to create an image containing text, using imagemagick. The comment made by Severin improved upon the original snippet by cropping the image to just fit around the text.

One could use this in a script if you just set the following variables: width, height, fontsize, text and filename. I could have added another variable for font, but that would have made the example code below less informative.

convert -size ${width?}x${height?} xc:transparent -font /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed.ttf -fill black -pointsize ${fontsize?} -draw "text 0,${fontsize?} '${text?}'" -trim +repage ${filename?}.png

LaTeX and variables

One of the neatest things about LaTeX (except for the automagic table of contents generation, ease of use when it comes to references, and never having to worry much about typesetting) is that it really is a markup language. A markup language where you can define your own “macros” (commands as they are called in LaTeX). And these commands can be just as simple or complex as you have the skill to make them.

So for instance, if you are writing something in LaTeX, and you find that you have to write the same thing over and over again, you could define a new command which prints that for you wherever you call the command (this of course relies on that what you are writing many times is longer than the name you give your command, otherwise it wouldn’t make much sense. Unless of course this something you are repeating, may be subject to change later, and you don’t look forward to doing a search / replace across the entirety of the document(s).

I remember that our group used this during a semester at ITU, but then I “rediscovered” it this Monday as I embarked on a small writing project, being unsure if I liked the names I’d given my characters.

So now I have a “characters.tex” file, which just defines a couple of commands. These commands, in turn, do little more than return the name I have currently given the character. characters.tex is then imported into the main file (“novel.tex“) and whenever I need to call a character by name, I just use the command I defined for that character.

This question over at Stackoverflow.com helped me with an answer:

\newcommand{\protagonist1}{Tony}

I.e. We call the command \newcommand which takes two arguments, whereof the first is the name of the new command (in this case \protagonist1) and a command body, what the new command should do, which, in this case simply is to output the string “Tony”.

Ok, protagonist1 sounds kindof silly, and perhaps I should have named the command nightclubOwnerFname instead, but that would have been a fingerfull to type.

What you take away from all this is that if I ever decide to rename Tony to… iunno, Mark? I will only have to change it in one place, the characters.tex file.

To include a file in LaTeX you use:

\input{characters}

Why the “.tex” from “characters.tex” should be omitted in the input command I have no idea about, but that’s how I learnt it, and it works. One day I should really sit down and figure that one out.

Finally, to use the command inside your text you just write your stuff, but instead of writing the name you call the command:

She looked at \protagonist1{} in disbelief.

That’s pretty much all there is to it. Ain’t LaTeX neat?

Creating diffs in git

I started looking into fugitive but hit a brick wall smack dab in the beginning of the adventure as I’m running Arch, and its version of git was just slightly newer than that of p4bl0.

Once I got fugitive running, I wanted to get it to handle markdown (i.e. parse the markdown marked up as a part of the process of generating the published html), which had some unintended consequences for the <title> tag (i.e. markdown had already parsed the first line in the file, which is used as the post title) and this resulted in <title><p>my post title here</p></title>… that ain’t so good ;)

The upside to it was that I got to do a little digging around in code (which I need to get better at anyway) and I ended up solving that little problem (but that introduced a bug (yes, I suck, should’ve tested more first) but I have submitted another patch which should undo all my stupidity and make it right. This time I have done more testing ;))

BUT, it also meant that I needed to generate a diff that p4bl0 could use to patch fugitive. This blog post gave me all I needed to know, i.e.:

$ git diff --no-prefix > patchfile

Automatically mounting removable media in Arch

Although it can be reckless to automount stuff (because you never know where that USB stick has been ;)) it can be nice (comfortable) to have it all done for you, and that’s where autofs can help you.

Links

http://make-everything-ok.com/

Update: fixed silly typo, thank you mina86

2011w26

Sunday, July 3rd, 2011

How silly of me… I totally forgot to publish last weeks summary yesterday. So without further ado, only one day late:

bashPhotoGallery

I don’t know how I get myself into these things… all of a sudden I found myself needing a, reproducible, way of setting up a photo gallery, complete with thumbnails and affixing a content license to the images.

When it comes to creating a batch of thumbnails, imagemagick is the tool to use. Accept no substitutes!

I am also going through a little crush on markdown.

Getting rid of UTM variables

I am not all that fond of those UTM variables that some “services” tack onto their links in order to better track where people are coming from (I understand why they’d do it, but I have no interest in being tracked, even if all they want to know is whether or not their push to be visible on $SOCIAL_MEDIA_SITE_OF_THE_MONTH is successful.
I know that I by accident stumbled upon a blog post outlining how to get rid of them programmatically, and I also know that I for some reason or other couldn’t find it, but without being too paranoid, I can understand why Google might not want to help people find the knowledge to do that ;)
In any case, I stumbled upon two resources for doing just that, but I think that was more due to dumb luck than any concentrated effort on my part, actually, it was quite by accident while looking for something else.

Bash is so cool!

I already knew about echo {A,B,C,D} (great in conjunction with mkdir -p, but I have realized that bash is cooler than that.
echo {A..D} delivers the same result, without the need to explicitly specify all of the chars I want expanded. Nice!

makefile blogging :: comments

psquid had a rather interesting solution to blog comments. I’ll have to think more about this. I don’t know how I feel about letting some other party (even if it is as nice a party as identi.ca) host “my” comments, but it is totally worth considering.

Wednesday

All in all a pretty good day. Got to assist razor with both vim and LaTeX skills (the student has become the master, yay!), got some writing out of my head, and ended up doing a little Test-Driven Python hacking.

And although I was a bit sceptical about OlofB‘s pyTDDmon, especially about it blinking continuously, which could get really old really fast, at first, I have to say that it has kindof grown on me since.

Batch-cropping screenshots

Tuesday, January 4th, 2011

Yesterday I set out to create a couple of screenshots I needed for an idea I’ve gotten. What I wanted to screenshot was vim.

For some reason or other, scrot -s followed by manually clicking on the window to screenshot didn’t work. The resulting screenshot just showed an empty terminal (or not even that, just the background (shining through the transparency of my terminal).

Screenshot:ing the entire screen produced the desired results, except for showing everything else on the screen.

First idea was to use GIMP and simply cut out and save the portion of image I wanted, and GIMP is great and all, and I could probably have automated it somehow, but truth be told, on the 10″ screen of my netbook, that was less than optimal.

Imagemagick does have several interesting features, among them cropping.

So this is what I ended up doing:

  1. Get the width and height of the portion of the screenshot I wanted to extract, using GIMP
  2. Get the (x, y) coordinate pair for the upper left corner of the portion of the screenshot I wanted to extract, again using GIMP
  3. Make backups of all the screenshots ( $ mkdir backup; cp *.png backup/ )
  4. Using a for-loop, calling on imagemagick to crop the screenshots, one file at a time
$ for f in `ls *.png`;
do
    convert -crop 511X293+513+0 "$f" "${f%.png}.cropped.png";
done

i.e crop a rectangle 511 pixels wide, 293 pixels high, whose upper left corner is at (513, 0).

The resulting filenames weren’t all that impressive (e.g. screenshot-1.png.crop.png) but it was a burden I was willing to bear, given how easy it would then be to rename them using mmv.

Just a small
$ mmv "screenshot-*.png.crop.png" "screenshot-#1.cropped.png"
and the “.png” in the middle was gone :)

(updated (2011-02-18 23:25) with great tips from Nicolas.)

My software stack revisited – (Multi)media and entertainment

Thursday, December 23rd, 2010

I am probably abusing the English language with this use of the word multimedia, but I just couldn’t find any better way of describing audio, video and images in a word… sorry :P

Video

For playback I mostly use mplayer, but for some reason or other, keep VLC around, although I can’t really explain why.

I’ve successfully used k9copy to make backups of my DVD-collection, works great :)

Audio

Ok, so you know I like living on the command line, right? So it won’t come as a surprise to you when I say that I used to use cplay? I still keep it around, it really is quite nifty, but the lack of an easy (and documented) way of interacting with it externally (say, through keyboard shortcuts) made me finally look elsewhere (having to jump to a tag in order to pause the music when the phone rings isn’t fun).

So when I discovered moc (Music On Console) I was pleased. I could script it to my heart’s delight. Even better: it doesn’t need its curses-based UI to function, so I only bring it up if I want to edit the playlist, hit q when I’m done, and kill the terminal, and the music keeps flowing.

And for converting videos or audio between formats (or extracting the audio from a video) ffmpeg is the tool to do the job.

For finer editing of audio files, I use Audacity.

Images

For image viewing, I use eog and geeqie, which does a good job of complementing each other.

And although not a regular activity of mine, for a small project I was doing in my spare time recently I got the chance to use both Gimp and Imagemagick.

I’ll see to it tonight that I’ve used Inkscape more than three times so that I can honestly put it on the list as well, it deserves to be there.

Entertainment

I find astronomy quite fascinating, and although that is on a very amateurish (to the point that I haven’t bought a telescope or anything yet) level, Stellarium is a superb software.

festival, a text-to-speech synthesiser, might not at first glance seem all that entertaining, but it can indeed be, not to mention I actually got use for the accompanying package text2wave when setting up notifications for my instant messenger (audible hints that specific people have come online).

No list outlining entertainment would be complete without a mention about games and since I do, from time to time, need to get my mind off things, games provide the perfect distraction.

The bsd-games package contains a couple of CLI apps, both semi-useful stuff, and some games. Wump is my favorite game from that package, mostly due to fond memories from ITU.

Games are otherwise still one of the big problems for GNU/Linux although indie-developers like the ones who come together in the Humble Indie Bundle, are making good progress in making gaming platform-independent.

Finally I find programming quite entertaining, but that will be the topic for the next post, so I’ll end things here.

:wq