2007/08/30

ScreenSpy: New Release V1.1

ScreenSpy: New Release V1.1




You can download it here:

ScreenSpy v1.1 (Win, Unix, MacOS) -- Includes source code.

ScreenSpy v1.0 (Win, Unix, MacOS) -- Includes source code.


Usage:

java -jar ScreenSpy.jar ftp.domain.com username password 1000

or, for the win32 .exe:

Screenspy.exe ftp.domain.com username password 1000

This would start sending the screenshots to "ftp.domain.com" once every second.


Changes:



V 1.1:

-Smarter naming of pictures (for example: Thu_Aug_30_06-57-19_.jpg)

-Always delete the file on exit. X

-Option to select the amount of time in between screenshots.



V 1.0:

-Initial release





It will run on all major platforms give you have a java virtual machine installed (www.java.com). I also included a win32 binary.



Have fun!

[Generated at: 2007_08_30_07h41m06s]

2007/08/20

Draw simple graphs with DOT

A quick and painless way to generate directed and undirected graphs under windows / Linux.
The DOT language is useful because it can be easily generated by a script and hence can be used to automatically generate documentation.
It is also useful to quickly draw a professional looking graph without having to use a graphical interface.

Example:



Here is a simple graph:


Do you get it? Visit my blog often and you will never need time or ideas again to solve your problems!

Here is the .dot script that generated the graph.

Source Code: [File=Graph.dot]



digraph G
{
Computer -> David;
Problem -> David;
Time -> David;
Idea -> David;

{rank=same; Problem; Idea; David; Computer; Time;}

David -> Blog;
Problem -> You;
Blog -> You [dir=both, color=lawngreen, style = bold];
You -> Solve;

You [shape=box]
Problem [shape=tripleoctagon, color = red, style=filled, fillcolor=yellow]
David [label = "David Malin", shape=box]
Blog [label = "davidmaling.blogspot.com", shape=diamond, fontsize=15, color=steelblue3]
}


The following command will compile the .dot file into a png image:


dot -Tpng -O Graph.dot


Neat no? The program (dot) can be obtained here:
http://graphviz.org/

You can read the wikipedia entry about dot:
http://en.wikipedia.org/wiki/DOT_language

... or download a more complete documentation here:
http://graphviz.org/Documentation/dotguide.pdf

Graph on!

P.S: Send me your home-made graph and I will post it on the blog. :)

[Generated at: 2007_08_21_01h34m18s]

2007/08/16

pyScreenSpy, a Python implementation using Java libraries & JPython

I love Python, I dislike Java. But Java is maintained by a large corporation and has some tools that Python does not. It is possible to write a program in Python, using Python's core library and Java's library in the same program and compile it in a Java bytecode executable. All you need is to download and setup JPython. Here are the implications of developing a program using JPython:

Advantages:

  • Use both Java's and Python's libraries seamlessly in the same program.
  • Will work on all platforms that Java works.
Disadvantages:
  • Java's virtual machine is long to load (~3sec compared to Python's ~0.1 sec)
  • Some functionalities of Java and of Python are not available in JYthon, and the documentation about that is not very good.
As an example, I re-coded parts of the JScreenSpy application that I published a few days ago using JPython in 21 lines. This is just an example, I will re-release a fully working and ameliorated version (1.1) of JScreenSpy in Python in the following days.

Here is the source file, you can execute it using jpython pyScreenSpy.py
#Pythons imports
import os

#Java Imports
from javax import imageio
from java import awt
from java.awt import image
from java import io

#Determine current screen size
toolkit = awt.Toolkit.getDefaultToolkit();
screenSize = toolkit.getScreenSize();
screenRect = awt.Rectangle(screenSize);

#Create screenshot
robot = awt.Robot();

#Take ScreenShot
image = robot.createScreenCapture(screenRect);
imageio.ImageIO.write(image, "jpg", io.File("test.jpg") );
21 lines, in Python, using Java's libraries. How cool is that? Very!

Easily Encode your Videos / DVDs with MPlayer/Mencoder

This entry will show you how to easily encode videos with MPlayer / Mencoder. MPlayer is a good, free, open-source, cross platform player / encoder that can make a local copy of your DVDs and transcode your videos to a format your embedded player (iPod, Cowon D2, ...) can read.

Video Codecs:

First, I have to talk a little bit about video codecs. In a nutshell, there are two main formats in which you should consider encoding your videos:

1. Xvid: Free and open source, widely used, your dvd player can probably read/play the transcoded video files.

2. H.264 ~30% more efficient than Xvid, but not yet widely spread. You should probably not use this format yet unless you do not care about being able to read the files on your dvd player. I do not recommend this format, but it is the one I use for my personnal video library :P.

You can get MPlayer/Mencoder for your platform here.

Commands:

These commands will encode / rip the video files into the Xvid format. To use other formats, please refer to the Mencoder documentation.

[For Windows] Once Mplayer / Mencoder is installed, go into the directory that contains the Mencoder.exe binary.

The you can use the following commands:

Normal Encode:

resize video (fixed):
mencoder input.avi -o output.avi −vf scale=500:375 -oac copy -ovc xvid -xvidencopts bitrate=1500

encoding video using mencode:
mencoder input.avi -o output.avi -oac lavc -ovc xvid -xvidencopts bitrate=1500
mencoder input.avi -o output.avi -oac lavc -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1500
mencoder input.avi -o output.avi -oac copy -ovc lavc -lavcopts vcodec=mjpeg:vbitrate=4000


join multiples files:
mencoder -oac copy -ovc copy -idx -o output.avi *.avi
or
cat a.avi b.avi > all.avi
(and then:)
mencoder -forceidx -oac copy -ovc copy all.avi -o all_final.avi

build slideshow from .jpg:
mencoder "mf://*.jpg" -mf fps=0.2 -vf scale=640:480 -o output.avi -ovc xvid -xvidencopts bitrate=1500

Rip DVDs:

keep original (mpeg-2) encoding:
mencoder dvd://1 -dvd-device D: -o out.avi -oac copy -ovc copy

orig.size, with compression:
mencoder dvd://1 -dvd-device D: -o out.avi -oac lavc -ovc xvid -xvidencopts bitrate=1500

resizing, with keeping aspect ratio (572 x abc):
mencoder dvd://1 -dvd-device D: -o out.avi −vf scale −zoom −xy 572 -oac lavc -ovc xvid -xvidencopts bitrate=1500

resizing, with keeping aspect ratio and reducing framerate:
mencoder dvd://1 -dvd-device D: -ofps 23 -o out.avi -vf scale -zoom -xy 320 -oac lavc -ovc xvid -xvidencopts bitrate=2000
mencoder dvd://1 -dvd-device D: -ofps 23 -o out.avi −vf scale −zoom −xy 572 -oac lavc -ovc xvid -xvidencopts bitrate=1500


resizing, force 640x480:
mencoder dvd://1 -dvd-device D: -o out.avi −vf scale=640:480 -oac lavc -ovc xvid -xvidencopts bitrate=1500

Misc:
If you get error messages about the audio compression, just replace "-oac copy" by "-oac lavc" or "-oac mp3ame"

2007/08/10

SQL Basic Commands

SQL is a computer language that can be used to store and manage data. It can be used to store and retrieve information without having to worry about the internal representation of the data, SQL will choose the best way to manage it. Now, with the release of SQLite and bindings for most popular programming languages, it can be very useful in small applications as it will store the database locally and hence does not need a server to work. I have used it in many small applications, one of which I will probably release in this blog in the following weeks.

There are many free version available, my two favorites being PostgreSQL and SQLite. MySQL is freely available, but it has the drawback of being licensed under the GPL, which means that if you used it in your application, you *have* to release the source code.

Here are some of the commands you need to get started with SQL:

Show databases:
SHOW DATABASES;
Change database:
USE dbname;
Create table:
CREATE TABLE tablename (name VARCHAR(20));
Create database:
CREATE DATABASE dbname;
Create user:
CREATE USER username;
CREATE USER username@localhost;
Remove user:
DROP USER username;
Rename table:
DROM TABLE tablename;
Grand access rights to the database:
(http://dev.mysql.com/doc/refman/4.1/en/adding-users.html)
GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost' IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%' IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost'; #No password
GRANT USAGE ON *.* TO 'dummy'@'localhost'; #No password, has to log from localhost, usage = no privileges
Notes:
[...]@localhost --> Allows the user to log on FROM localhost.
GRANT ALL PRIVILEGES ON *.* TO 'youUsername'@'localhost';
Select data:
SELECT * FROM tablename;
Delete specific data in a table:
DELETE FROM tablename WHERE property_name='bob';
Delete all data in table:
DELETE FROM tablename;
TRUNCATE tablename;

With these commands you can start building your own custom application. I will post more information on how to embed it in a python program soon.

2007/08/09

ScreenSpy: Record what your Computer is Doing while you are Away

I recently wrote a small program in Java that takes a screenshot every second or so and sends it to a FTP of your choice. It could be used to check which websites you children are visiting when you are away, or if they are approached by inappropriate individuals on myspace. I didn't make it stealthy, the goal is to give an incentive to your youngsters not to visit prohibited websites, not to catch them being naughty.

You can download it here:
ScreenSpy v1.0 (Win, Unix, MacOS) -- Includes source code.

Usage:

java -jar ScreenSpy.jar ftp.domain.com username password

or, for the win32 .exe:

Screenspy.exe ftp.domain.com username password
It will run on all major platforms give you have a java virtual machine installed (www.java.com). I also included a win32 binary.

Have fun!

By the way, I am looking for others fellow bloggers to contribute to this blog or to contribute to the source code of my projects. Leave a comment if interested.

*Q&A*

Matt:
If the screen has been idle, does it save space not hold off sending anything?

A:
Unfortunately not. It is a feature that could be added. Anyone has a good idea on how to implement that in Java? Save checksums of the pictures and compare them? If lots of people feel strongly about this I might try to find a solution...

2007/08/07

Batch Resize and Compress your Images with ImageMagick

.

Web Page Moved!

New location: http://david-web.appspot.com/cnt/CompressImagesImageMagick/

Old Entry (Information Might Be Deprecated)

It regularly amazes me how little people know about the capabilities of the .jpeg .jpg format and how, as a result, their image libraries are easily four to five time as big as they need to be.

The method that I am going to show here is going to reduce the size of every picture in a directory to about 500k. This compression will reduce the quality of the picture, but not enough to make it noticeable to the naked eye.

First of all, go download the excellent ImageMagick software at:
http://www.imagemagick.org/ (dl: win unix)

Once the software is installed, go to the directory containing the files (it would be wise to back-up your pictures first) and type in the command line:


mogrify -resize "2048x2048>" -quality 75 *.jpg

What it will do is that it will take each picture individually, resize it to 2048x[...] pixels and change the quality setting. I chose 75 because it yields the greatest compression/quality loss ratio. Check it out for yourself, I am sure you can't tell the difference between the compressed picture and the original. This typically reduces the size of a 3,000 Kb picture to under 500Kb.

Here are some other cool things you can do with ImageMagick intalled:


Get the picture properties:
identify -verbose
abc.jpg

Compare the diff between two pictures:
compare -metric MAE First.
png Second.jpg diff.png

Burn a logo into a pic:
(more on composing: http://www.imagemagick.org/Usage/compose/)
(Use white background)
composite -gravity
NorthWest -compose color-burn logo.png image.jpg out.jpg

Write text on all pictures:
(x,y ,
dx,dy) 0,0 = original size
mogrify -draw "image color-burn 4,4 0,0 'logo.png'" *.jpg
convert -draw "image color-burn 4,4 0,0 'logo.
png'" *.jpg out.jpg

More at:
http://www.imagemagick.org/script/composite.php
http://www.imagemagick.org/Usage/