Tuesday, May 20, 2008

Photoshop Vector Sunburst

I have been using sunburst in many of my works. But having to make them repeatedly, led me to see up a tutorial on vector sunburst. In most searches, I landed up here http://www.slicktutorials.com/vector_sunburst. Though it is a good way, but transforming each end of the flower shape is quite tiring. Suddenly, I came across a tip that helped me to create it much easily and faster. So here it is:
  1. Open Photoshop and a new document. I took 400 x 400 pixels.
  2. Set the foreground color to #ff9900 and background to white. Fill the background with white.
  3. Select the Polygon Tool and draw a triangle from top with one edge at the center of the document. Transform (Edit > Free Transform or ctrl + T) the triangle to look like a sunray. See my image below:
  4. Select the Path Selection Tool (A) and click on the vector layer. All the three edges should now have the anchor points.
  5. With the anchor points on, we will transform the layer (Edit > Free Transform or ctrl + T). You should see the bounding box with nine reference points and the middle one selected.
  6. Drag the middle reference point to the middle of the bottom border. Changing the reference point will actually move the center of the object to the new position.
  7. In the set rotation text box, enter 20. Now your shape should have rotated 20 degrees clockwise with the center of the shape at bottom middle border. Hit enter twice to apply the transformation.
  8. Keep the anchor points selected and press ctrl + shift + alt + T. This should create a new set of triangle with a further 20 degree rotation. Repeat ctrl + shift + alt + T, till you complete a circle and get your Sunburst.
  9. Now, you can unselect the vector shape and apply any blending options that you want to apply.
In this method, by keeping the anchor points selected and then doing a transform, you are adding to the vector shape within the main layer itself. This will help you in easily saving the shape as a custom shape.

Alternately, you can just transform & rotate without selecting with the Path Selection Tool, hitting ctrl + shift + alt + T to get individual duplicated layers.

Another beautiful realistic sunburst tutorial I found is here.

Monday, May 12, 2008

Using Perl CGI with MS-Access on IIS

Though I was working on Perl for the past 1.5 years I was unaware of a few simple permission settings that may be required on a Windows machine with IIS to ensure that a Perl CGI program interacting with MS-Access Database with the help of DBI package perfectly works.

Let us make a test case. We will require two files -
  1. main.html - a simple html form
  2. update.pl - Perl script that would be called once you submit the html form. This script would update the data into an MS-Access database - emp.mdb
main.html

<form id="form1" name="form1" method="post" action="update.pl">
<p>Employee Id:
<input name="emp_id" type="text" id="emp_id" />
</p>
<p>Employee Name:
<input name="emp_name" type="text" id="emp_name" />
</p>
<p>E-mail:
<input name="mail_id" type="text" id="mail_id" />
</p>
<p>
<input type="submit" name="Submit" value="Update" />
</p>
</form>

The html form as you can make out is a small data entry form with three text fields for filling up the details like employee id, name, email address and once you enter all these details, you click on the submit button.

update.pl

use CGI qw(:standard);
use DBI;

sub validEmpId
{
print "Validating Employee id";
if($emp_id !~ m/\d*/)
{
return false;
}
else{
return true;
}

}
sub validMailId
{
print "validating mail id";
if($mail_id =~ m/\w+\@\w+\.com/)
{
return true;;
}
else
{
return false;
}
}
$emp_id = param("emp_id");
$emp_name = param("emp_name");
$mail_id = param("mail_id");

if($emp_id =~ m/[a-z A-Z]/)
{
exit;
}
elsif($mail_id =~ m/\w+\@\w+\.com/){
##store it in the database
$dbh = DBI->connect("DBI:ODBC:emp");
$sth = $dbh->prepare("Insert into emp_data(Id,Name,Mail_ID) values($emp_id,'$emp_name','$mail_id')");
$sth->execute();
$sth->finish();
$dbh->disconnect();
}
else{
exit;
}

The data entered through the html form, is passed on to the update.pl Perl script which inserts the data into the database. You could also use the sub-routines of the program for some validations like ensuring the Employee ID is a number and the mail ID is in a correct format etc., and then insert the data into the MS-Access database.

Settings:
  1. The html file, the Perl script file and the emp.mdb (MS Access database) resides in a folder.
  2. Appropriate DBI/ODBC Perl packages are available.
  3. Appropriate ODBC DSN (Data Source Name) called “emp” is created , connecting to the MS-Access Database called “emp.mdb”, which has a table called emp_data which is supposed to store the entered employee details. (Done using the “Data Sources(ODBC)” option under the Control Panel -› Administrator Tools)
  4. Also created a virtual directory on the IIS and linked to the physical directory where the html and the Perl script resides (Eg.: A virtual directory called “ss” was created which was linking to the actual physical directory where the html, Perl and the mdb files were residing) (Done using the “Internet Information Services” option under the Control Panel -› Administrator Tools)
How the program is supposed to behave: Once the main.html file is accessed through the browser, the Data Entry Form is to be shown. Once all the data is entered into the text fields and form submitted, the data is supposed to be passed to the Perl script file (update.pl) which would in turn update the data into the corresponding database.

How was it actually behaving: The form shows up properly, but when the data was entered and submitted, it throws up an error, like:

CGI Error

The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:
DBI connect('emp','',...) failed: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (SQL-IM002)(DBD: db_login/SQLConnect err=-1) at C:\mini-project\store.pl line 40
Can't call method "prepare" on an undefined value at C:\mini-project\store.pl line 41.

Solution:
  • The physical directory where you store all your files and then link it up with the virtual directory in IIS has to have some specific permissions settings. User called IUSR_, IWAM_ have to be given full permissions (at least read and write). (right click on the folder -> properties -> security tab -> add -> advanced -> find now -> choose the user earlier mentioned and give them full/appropriate read and write access)
  • Then in the data source name that we create in the ODBC, we need to create it as "system DSN" instead of "user DSN" and then give enough login and password details if required. For MS Access the default user is “admin” and password is NULL password.