ImageMagick command line: create smaller version of images

I wanted to create smaller versions for many large images in a single directory and

  • have a file name for the new file that is derived from the original file name (to be able to easily identify the image or link them to full size versions later)
  • keep the original aspect ration of the image (unlike many thumbnail programs)
  • never scale the images up (i.e., only change them if they are larger than target size)

It turned out it was easiest to do this on the command line, using the convert program from ImageMagick. Here is what I did:

for FILE in *; do BN=${FILE%.*}; TARGET="${BN}_smaller.jpg"; echo "Converting file: $FILE to: $TARGET"; convert "$FILE[800x>]" "$TARGET"; done

 

Here is a detailed step by step explanation of what this does:

for FILE in *; do                        # Loops over all files in directory
    BN=${FILE%.*};                       # Extract part of file name before the first dot
    TARGET="${BN}_smaller.jpg";          # Construct output file name (and define output format with file extension)
    echo "Converting file: $FILE to: $TARGET";     # Tells user what we are doing atm
    convert "$FILE[800x>]" "$TARGET";    # perform scaling to width of 800 pixels (only shrinks images, never scales them up)
done                                     # ends the loop

 

Hope you find this useful!

Advertisements
Posted in general, Photography | Tagged , , , | Leave a comment

Enable code suggestions for Java in Netbeans 8 on every character entered

In the NetBeans 8 IDE, by default you get automatic code completion suggestions when typing a dot. You can also trigger the completion manually at any time by pressing CTRL + SPACE.

Pressing that key combination all the time can get annoying quickly though. So here is how to get it on every character you enter (or key you press):

First, go to Tools => Options. Then Select Editor in the top bar, and go to the Code Completion tab. You should now see this menu shown below. Make sure to select your language, in my case Java, in the drop down list:

netbeans_code_completion_select_java_here.png

 

Then enable the following two checkboxes named Auto Popup on Typing Any Java Identifier Part and Subword completion:

netbeans_code_completion_activate_both_checkboxes.png

Now you should get auto-completion as visible below:

 

netbeans_code_completion_result.png

That’s it, enjoy!

 

 

Posted in coding, troubleshooting, tools, IT and computers | Tagged , , , , , | Leave a comment

Lettuce tests with Python: make lettuce print to stdout

The lettuce BDD framework swallows the output of your steps if they try to print to stdout, so you will never see the output of the print in a step like this:

 
@step('Cell number (\d+) should (read|contain) "([^"]*)"')
def cell_group1_should_read_or_contain_group2(step, cell_number, read_or_contain, expected_text):
# your test logic here
print "somevar is now=" + some_var
assert_true(step, 15 == some_other_var)

If you need to print the variable during test development, e.g., because it contains the innerHMTL of some complex element, you can force lettuce to print it by abusing an always failing assertion:

@step('Cell number (\d+) should (read|contain) "([^"]*)"')
def cell_group1_should_read_or_contain_group2(step, cell_number, read_or_contain, expected_text):
# your test logic here
assert True == False, "somevar is now=" + some_var
assert_true(step, 15 == some_other_var)

It’s maybe easiest to run lettuce on the command line for this, e.g.,

cd my_app/test/
lettuce features/my_tested_feature_123123.feature

Hope this helps.

Posted in IT and computers, Software Design | Tagged , , | Leave a comment

WordPress mini theme published: customization of twentyseventeen theme for text links in footer menu

I really like the new WordPress default theme called twentyseventeen. I just needed some small customizations for creating professional websites in Germany.

As you may have heard, lots of things are regulated in Germany, and you may want to have named text links for stuff like the imprint and privacy information for a professional website.

My custom child theme twentyseventeen-textfooter allows you to have that instead of the icon links which are usually displayed in the secondary menu (because it is intended as a social media menu).

Here is a preview image (text links in red circle):
preview_twentyseven_child_theme_text_footer_menu.jpg

The changes are trivial, but if you are interested, get the theme at GitHub.

Posted in coding, general, IT and computers, web design | Tagged , , | Leave a comment

Node.js package published

In my new job I am doing front-end coding with React.js, and every Javascript programmer needs to have some package published at npmjs.com I guess. 😉

So here is my first package: js-object-util

It is inspired by the Immutable API but works for plain Javascript objects. You can use it to easily check for and retrieve properties of deeply nested objects. Let’s have a closer look at the usage:

var objectUtil = require('js-object-util');

// some deeply nested example input
const book = {
	publisher: {
		name: "dpunkt",
		address: {
			city: "Heidelberg",
			plz: 69123
		}
	},
	title : "React",
	year: 2015,
	properties: {
		includes_ebook: false,
		whatever: null,
		dunno: undefined
	},
	readers: [
		{
			type: "user",
			name: "Johnny",
			age: 32,
			nickname: null
		},
		{
			type: "user",
			name: "Brad",
			age: 13,
			nickname: "Bratze"
		}
	]
};

// let's go
var keyExists;
keyExists = objectUtil.hasIn(book, ['publisher', 'address', 'city']);	    // true
keyExists = objectUtil.hasIn(book, ['publisher', 'address', 'notthere']);   // false
var value;
value = ObjectUtil.getIn(book, ['year']);		   // 2015
value = objectUtil.getIn(book, ['readers', '1', 'name']);  // Brad
value = objectUtil.getIn(book, ['readers', '1', 'notthere'], 'alternate');  // 'alternate'

This is cool because you don’t have to do these stupid step-wise tests for the existence of certain properties anymore.

I hope you like it. See js-object-util for installation instructions. Unit tests and coverage stats are included, the source code is at github. License is MIT.

Posted in coding, IT and computers, tools | Tagged , , , , | Leave a comment

Fun with processing.js

I started checking out various visualization tools for the web during the last few months. A project which I found very interesting is processing.js. This is a JS port of the processing language, an easy-to-use language to write visualizations or interactive media stuff. It seems it’s mainly used for visual art stuff.

You can see some example processing.js code here:

 

processing_code

 

The page header animation at the processing website inspired me to create a small game, which I called PRace. Here is a screenshot:

prace_web

It’s a 2D side scroller. You are the red guy on the left, and the goal is NOT to crash into the blue guys coming at you from the right — BUT flying close to them gives you points.

The best thing is that you can give the game a try yourself with a modern browser:

http://rcmd.org/projects/prace/

The code can be found at Github: https://github.com/dfsp-spirit/web/tree/master/processingjs/prace

 

Enjoy!

 

Posted in coding, general, IT and computers | Tagged , , , , | 1 Comment

Architecture visualization in the Quake 3 engine

I was recently given a bunch of 2D plans of a large building. They were floor plans for the 5 stories, plotted on paper. I’m pretty good at imagining the 3D object from 2D plans, but in this case, I thought some 3D visualization might be helpful. So for everybody involved in the project, I built the whole thing in the Quake 3 engine on a rainy Sunday afternoon some months ago when I was ill and had nothing better to do.

Here is the front view:

q3_arch_1

Here is the back of the building:

q3_arch_2

And finally, a small section which already has some windows:

 

q3_arch_3

This was a fun project for a day that made some people happy.

Here is a final shot showing the scene in the Quake level editor GtkRadiant:

q3_arch_editor.jpg

 

Posted in general, Level Design | Tagged , , , , | Leave a comment