Instant transparent PNG generator v0.2

Earlier, I needed a semi-transparent png. I couldn’t be bothered to fire up Photoshop, couldn’t be bothered to steal one from another project, couldn’t find a png maker online, and yet I could be bothered to write an app to do it for me and share it with the world. F’kn stupid huh?

I’ve still not done the task I wanted it for in the first place!

The project utilises jQuery 1.4.3, jQueryUI 1.8.6 slider and Stefan Petre’s jQuery Color Picker plugin:

jQuery: The Write Less, Do More, JavaScript Library

jQuery UI – Slider Demos & Documentation

ColorPicker – jQuery plugin

Assistance with png generation garnered from this Codecall Forum post by AfTriX

This is a first, but fully functioning, release. As such, it still requires a decent user interface, and the code needs commenting, but it’s pretty simple stuff, thanks to Jquery. The png creation (once you get it to create an initial transparent png, which is much harder than documentation would suggest) is very simple, and achieved in just a handful of lines.

[UPDATE 1321-13112010]

The interface has now been fully styled for a much more pleasant appearance, and to match the blog. It’s quite CSS3 heavy for the spankier effects, so of course looks best in an up to date browser.


I started by collecting the libraries and jigged the directory structure to my liking:

First up is the form and UI – this is actually html and Javascript, but I gave the file a PHP extension for forward compatibility.


As this code contains a complete HTML page, it’s a bit difficult to include in the blog, so here it is on paste bin:


A small hack is required to get the colorpicker to populate the hidden form fields with RGB values – there are of course other ways to do this, but as this hack is unobtrusive, and being jQuery will fail gracefully if this version of the plugin is used anywhere else, it seems the tidiest way to do it to me.

l.28 – 34 <<

l.28 – 40 >>

And the second half of it is the png script


The script in action


Source files

The custom jQuery UI files have been further reduced as much as possible – uneccessary images and CSS rules have been removed. This means this version of the UI plugin may not be suitable for use in other projects unless you just want a simple slider as in this case. Also the colour picker background image and css have been modified to simplify the interface slightly.

I’m releasing this as GPL – feel free to install, modify, whatever, as long as it is not sold or otherwise charged for, and, wherever you use it, be good enough to give me credit, retain my credits in the files and drop me a line.

Plesk 9.x – Access multiple databases with a single MySQL user

I have to set this up quite a lot for user sharing across multiple Joomla! sites. I will eventually get round to publishing the full instructions for that, but in the meantime I will start with this.

I got started on this with the aid of this post from Simple Steps:
Multiple mysql databases with single user
Fantastically useful as this is, it’s slightly out of step with Plesk 9 (or at least the config for my host), so for my reference and yours, here are updated instructions.

For the purpose of this example, we shall pretend we are going to add the user ‘ac_siteuser’ to the database ‘fh_testing’

Connect to MySQL

1. Using PuTTy, or your preferred terminal, connect to the server over SSH

2. Connect to MySQL as the admin user. Note in Plesk the MySQL user ‘root’ is replaced by ‘admin’
# mysql -u admin -p
You will be prompted for the admin password.

Add existing user to different database with permissions

3. Select the database named ‘mysql’
mysql> USE mysql;

If you need to check the permissions (all the ‘Y’s and ‘N’s in the INSERT statement below) against an existing user you can view the table like this:
mysql> SELECT * FROM db;

I found this to be necessary as the first time I attempted this, I receieved an error: ERROR 1136 (21S01): Column count doesn’t match value count at row 1

If you already have a lot of users the results may be hard to read, so to just view one user:
mysql> SELECT * FROM db LIMIT 1;+------+------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+| Host | Db   | User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Create_tmp_table_priv | Lock_tables_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Execute_priv |+------+------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+| %    | test | user | Y           | Y           | Y           | Y           | Y           | Y         | N          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | N                  | N            |+------+------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+

4. Insert the user into the db table with priveleges for the new database.
Having checked the privelege settings against those below and satisfying yourself they are good, you do the insertion:
mysql> INSERT INTO db VALUES('localhost','fh_testing','ac_siteuser','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N');

Note that to prevent access from any other server with this user, set the Host field to ‘localhost’ as in the above example. ‘%’ means ANY mysql connections will be allowed from ANY host. 

And that is it.

Or is it? Your sites can now access another database with that user, but you have no access to that user in Plesk or through Plesk’s PHPMyAdmin interface.

Add existing user and database to Plesk tables

4. Select the database named ‘psa’
mysql> USE psa;

5. Check the account_id of the user being added to the database
mysql> SELECT * FROM db_users;+----+------------------+------------+-------+| id | login            | account_id | db_id |+----+------------------+------------+-------+|  1 | ac_siteuser      |          3 |     2 ||  2 | ac_testinguser   |          4 |     3 ||  3 | fh_testinguser   |          6 |     4 |+----+------------------+------------+-------+

In this case, the id of user ‘ac_site’ is 3

6. Check the id of the database
mysql> select * from data_bases;+----+----------------+-------+--------+--------------+-----------------+| id | name           | type  | dom_id | db_server_id | default_user_id |+----+----------------+-------+--------+--------------+-----------------+|  2 | ac_livedb      | mysql |      1 |            1 |               1 ||  3 | ac_testing     | mysql |      1 |            1 |               2 ||  4 | fh_testing     | mysql |      1 |            1 |               3 | +----+----------------+-------+--------+--------------+-----------------+

In this case the id of the fh_testing database is 4

7. Insert user name, user account_id and database id into db_users table
INSERT INTO db_users VALUES ('','ac_site','3','4');

8. Finally exit and restart mysql
mysql> exit;

# service mysqld restart