How to auto rotate images based on EXIF Orientation tag?

How to auto rotate images based on EXIF Orientation tag-1Everyone of us probably has hundreds if not thousands of images taken with his digital camera or cell phone. When viewing these pictures on computer (or TV) you will find that lots of pictures needs to be rotated to be displayed correctly. Doing this by hand can really take some time. Luckily, I have found an easier way of solving this problem. It’s also very fast and easy to use!

Most of modern digital cameras (and cellphones) save many extra data to JPEG. That’s called EXIF data. Many useful information about how the picture was taken is stored in there. In sample I provided on the right you can see part of the EXIF data saying that the picture was made using my Nikon D50, that I didn’t use the flash and that exposure time is 1/250 sec and that focal length was 80mm. Beside that, there are many other details that are not displayed in this sample, and among those is Orientation tag that says how the camera was positioned in time of shooting.

Our mission is to automatically rotate multiple images in batch using data saved under that field. For that purpose I will use FastStone Image Viewer that you can download from my favorite software download site FileHorse.com. This software is free for personal use (professionals should buy a license). It’s really amazing piece of software for image manipulation (viewing, converting, cropping, re-sizing, watermarking – you name it!)

How to auto rotate images based on EXIF Orientation tag-2

Ok, once you’ve downloaded, installed and started FastStone Image Viewer, you need to find images that you need to rotate. Once in folder with images select them by pressing CTRL+A and then go to Tools – > JPEG Lossless Rotate -> Auto-Rotate based on EXIF Orientation Tag just like on picture above. A popup will ask you are you sure you want to do it, press yes and wait until your photos are auto rotated (if you have lots of photos or slower computer it can take some time to process them all). It’s easy as 1-2-3! Take a look at the samples below:

Before Rotation
How to auto rotate images based on EXIF Orientation tag-before

After Rotation
How to auto rotate images based on EXIF Orientation tag-after

Feel free to leave your comments in the comment box below!


WordPress stuck with “Briefly unavailable for scheduled maintenance…”

Today I went to update some plugins on one WordPress installation but then I accidentally closed the tab while update was in process. When I went back to WP admin or (to blog homepage) I was getting this error: “Briefly unavailable for scheduled maintenance. Check back in a minute“. Since I couldn’t access WP Admin my hands were tied and I could do anything. So I logged in at the FTP to see how the plugins folder looks like and is something damaged. And in www (pubic_html) folder I noticed file “.maintenance“. I made backup of it and then deleted it and reloaded the blog and – IT WAS WORKING AGAIN! And WP admin was working again! WordPress never stops amazing me!


Uncaught SyntaxError: Unexpected end of input error in Chrome

Today, while I was working with jQuery I ran on this error “Uncaught SyntaxError: Unexpected end of input” while troubleshooting my code in Chrome. And since Chrome it didn’t report error on any specific line I had to Google for it 🙂

And after opening few pages I found out that this error codes happens when you forget closing “}”. That can happen often when writing JavaScript and especially jQuery code. Locating that is not easy, especially if you’r code is sloppy and you have a lot of it. Luckily my code is always very nicely written so I got it solved quickly. But in case you’r code is really messy or is compressed (with some JavaScript compressing tool like jscompress.com) you can copy/paste your javascript code into jsbeautifier.org, click on “Beautify JavaScript” (select the options you want on the right side of the screen first) and see if all of the indentations are correct. Beautiful and Geeky.


How to setup and use iptables

What’s iptables?
Iptables is the current Linux firewall and routing service. It controls incoming and outgoing network

How to stop/start/restart iptables?
Basically just like any other Linux service:

# service iptables start
# service iptables stop
# service iptables restart

How to check if iptables is currently running?
Simply call service status and take a look at the result:

# service iptables status
Firewall is stopped.

If you run “service iptables status” and get “Firewall is stopped.” that means that iptables are not running and you should start it with “sertvice iptables start”. If you get some tables with bunch of geek stuff that means that iptables are running.

How to automatically start iptables service on Linux boot?
To enable iptables starting on boot run

# chkconfig iptables on

or run code below to disable it

# chkconfig iptables off

How to block IP address using iptables?
This will block IP from accessing your server. Be careful not to block your IP address.
In command below replace “192.168.0.4” with correct IP address.

# iptables -A INPUT -s 192.168.0.4 -j DROP

After blocking the IP address (adding it to the iptable rules) you must restart iptables calling:

# service iptables restart

How to unblock IP address using iptables?
Similar to blocking, just use ACCEPT instead of DROP:

# iptables -A INPUT -s 192.168.0.4 -j ACCEPT

And after allowing that IP you must also restart iptables:

# service iptables restart

You can also flush your iptables rules by using:

# iptables -F

This will remove all custom added rules.

How to see current rules?
Simply by running following command:

# iptables -L

How to save iptable rules?
Rules created with the iptables command are stored in memory. If the system is restarted before saving the iptables rule set, all rules are lost. For rules to persist through a system reboot, they need to be saved. To save rules, type the following command:

# iptables-save > /etc/iptables.rules

How to load iptable rules?
To load previously saved rules execute:

# iptables--restore < /etc/iptables.rules

How to load iptable rules on Linux boot?
There are few ways and can be different on different Linux distributions. This should work on CentOS. To load rules on system boot make file /etc/init.d/iptableslr

# vi /etc/init.d/iptableslr

and add these two lines to it:

#!/bin/bash
/sbin/iptables-restore < /etc/iptables.rules

The file needs to be executable so change the permissions:

# chmod +x /etc/init.d/iptables

Security by obscurity

This simple guide will help you secure your server in indirect way by hiding software versions from possible attackers. This can help you prevent many automated attacks and attacks based on software version number. If a hacker want’s to probe your system for hole he’ll start from collecting all version numbers from your running services. This guide will teach you setup common services not to give away their version numbers. This is called Security by obscurity and it’s not something to rely on but it can lower chances of getting your system hacked.

Apache (Web Server)
Let’s start with Apache first. It’s config file should at path

/etc/httpd/conf/httpd.conf

Open that with an editor of choice. I allways suggest Midnihgt Commander but you can use ant other editor like pico or vi. In Midnignt Commander open file for editing by pressing F4 while the file is selected.

Locate those two lines and set it as follows. If you cant find them – add them.

ServerSignature Off
ServerTokens Prod

Server Signature will remove the identification of Apache version from error pages, and ServerTokens will identify Apache as “apache” without version number or OS information. Save the file and restart the Apache.

service httpd restart

Named (DNS Server)
Next we will disable named from giving away his version. Open named config file at path

/etc/named.conf

Search for line

query-source address * port 53;

Add a line right below it with add (if it doesn’t exist)

version "Named";

Save and restart named using

service named restart

Exim (Email Server)
Next we will disable the version numbers in Exim. If you are not running Exim there is no need to do this section. Exim config is at path

/etc/exim.conf

and if it could not be located, it probably means that you do not use Exim. Search for

smtp_banner = "${primary_hostname

This is the welcome message for the email server. You can put anything in here. Here’s a sample message

smtp_banner = "${primary_hostname} MailServer \n\We do not authorize the use of this system to transport unsolicited, \n\and/or bulk e-mail."

Save the config and restart Exim.

service exim restart

Remeber this is just security though obscurity and you still need to keep the server updated! This is just going to stop some people from finding your server in the first place by automated scanning. It will not help at all if somebody is trying to actually hack the server.

Continue Reading