How can I rotate an image?


How can I rotate an image?

Probably not something you will want to do a lot of in ordinary day PHP use, but if you want to rotate an image use the well-named imagerotate function.

This takes the image to rotate, the angle of rotation, and a color to fill the blank space around the rotated image with.

Here’s an example:

<?php
$original = imagecreatefrompng(“myimage.png”);
$red =  imageColorAllocate($original,255,0,0);
imagerotate($original,50,$red);
header(“content-type:image/png”);
imagepng($rotated);
imagedestroy($original);
imagedestroy($rotated);
?>

CSS Positioning – Some pointers


1. Absolute Absolute positioning is absolute in relation to the parent element. In this case the parent element is the whole document, so the div is positioned absolutley at 0,0 and will apear in the top left corner.

2. Relative This positions the element relative to where it would have been in the document. Useful for moving something down or across a few pixels for example. In the diagram, the black dashed outline shows where the div would have been without positioning.

3. Relative and Absolute An example of absolute and relative positioning. The outer green box is positioned relative to where it would have been, whilst the inner box is positioned absolutely in relation to the parent green box.

4. float This is where the element in question “hovers” left or right, much like aligning an image left or right works in plain HTML.

6. 3 Column layout Here’s where it gets fun. Below is a classic 3 column layout with the left and right DIV floated correspondingly left and right, and the middle DIV without any positioning at all.

Different css for different browser


In an ideal world, you only need one set of CSS style sheets for your website, and those styles will work with every browser currently being used. This, as every web master soon finds out when he/she uses CSS, is a pipe dream. The modern browsers all have uneven levels of implementation of the CSS standards. As though this isn’t bad enough, their implementations are often buggy – and they don’t share the same bugs! And when you have solved that tricky bit, you find that your site has certain visitors (often your best customers) who, for various reasons, are using older browsers that have only rudimentary support for CSS.

What most (if not all) CSS-using web masters want is a way to specify that a certain style sheet is to be used by such and such a browser and not others, as well as to hide other style sheets from older browsers.

One of the easiest things to do is to specify that a certain style sheet be loaded only by IE 5, 6 or 7 (and later versions) and be excluded from those versions of IE.

Microsoft provides a non-standard extension that allows you to detect those versions of IE, and include or exclude code depending on those versions.

To cause (say) a CSS file like “ie6.css” to be loaded by IE 6 and not other browsers, use the following code in the HEAD section of your web page:
<style media=”screen” type=”text/css”>
@import “./css/style.css”;
</style>
<style media=”screen” type=”text/css”>
@import “./css/print.css”;
</style>
<!–[if lt IE 7]>
<link rel=”stylesheet” type=”text/css” href=”./css/ie6.css” media=”screen” />
<![endif]–>
<!–[if IE 7]>
<link rel=”stylesheet” type=”text/css” href=”./css/ie7.css” media=”screen” />
<![endif]–>
Here ‘style.css’ and ‘print.css’ is global. It’s a simple example. If you want to know more details please inform me. I think now you should be able to create a site that works fairly similarly under the browsers being used today.

Protection PDF File


This script allows to protect the PDF, that is to say prevent people from copying its content, print it or modify it.

Author: Klemen Vodopivec
License: Freeware

SetProtection([array permissions [, string user_pass [, string owner_pass]]])

permissions: the set of permissions. Empty by default (only viewing is allowed).
user_pass: user password. Empty by default.
owner_pass: owner password. If not specified, a random value is used.

The permission array is composed of values taken from the following ones:

* copy: copy text and images to the clipboard
* print: print the document
* modify: modify it (except for annotations and forms)
* annot-forms: add annotations and forms

Remark: the protection against modification is for people who have the full Acrobat product.

If you don’t set any password, the document will open as usual. If you set a user password, the PDF viewer will ask for it before displaying the document. The master password, if different from the user one, can be used to get full access.

Note: protecting a document requires to encrypt it, which increases the processing time a lot. This can cause a PHP time-out in some cases, especially if the document contains images or fonts.
Source

encrypted=false;
$this->last_rc4_key='';
$this->padding="\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08".
"\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
}

/**
* Function to set permissions as well as user and owner passwords
*
* - permissions is an array with values taken from the following list:
* copy, print, modify, annot-forms
* If a value is present it means that the permission is granted
* - If a user password is set, user will be prompted before document is opened
* - If an owner password is set, document can be opened in privilege mode with no
* restriction if that password is entered
*/
function SetProtection($permissions=array(),$user_pass='',$owner_pass=null)
{
$options = array('print' => 4, 'modify' => 8, 'copy' => 16, 'annot-forms' => 32 );
$protection = 192;
foreach($permissions as $permission){
if (!isset($options[$permission]))
$this->Error('Incorrect permission: '.$permission);
$protection += $options[$permission];
}
if ($owner_pass === null)
$owner_pass = uniqid(rand());
$this->encrypted = true;
$this->_generateencryptionkey($user_pass, $owner_pass, $protection);
}

/****************************************************************************
* *
* Private methods *
* *
****************************************************************************/

function _putstream($s)
{
if ($this->encrypted) {
$s = $this->_RC4($this->_objectkey($this->n), $s);
}
parent::_putstream($s);
}

function _textstring($s)
{
if ($this->encrypted) {
$s = $this->_RC4($this->_objectkey($this->n), $s);
}
return parent::_textstring($s);
}

/**
* Compute key depending on object number where the encrypted data is stored
*/
function _objectkey($n)
{
return substr($this->_md5_16($this->encryption_key.pack('VXxx',$n)),0,10);
}

/**
* Escape special characters
*/
function _escape($s)
{
$s=str_replace('\\','\\\\',$s);
$s=str_replace(')','\\)',$s);
$s=str_replace('(','\\(',$s);
$s=str_replace("\r",'\\r',$s);
return $s;
}

function _putresources()
{
parent::_putresources();
if ($this->encrypted) {
$this->_newobj();
$this->enc_obj_id = $this->n;
$this->_out('<_putencryption();
$this->_out('>>');
$this->_out('endobj');
}
}

function _putencryption()
{
$this->_out('/Filter /Standard');
$this->_out('/V 1');
$this->_out('/R 2');
$this->_out('/O ('.$this->_escape($this->Ovalue).')');
$this->_out('/U ('.$this->_escape($this->Uvalue).')');
$this->_out('/P '.$this->Pvalue);
}

function _puttrailer()
{
parent::_puttrailer();
if ($this->encrypted) {
$this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
$this->_out('/ID [()()]');
}
}

/**
* RC4 is the standard encryption algorithm used in PDF format
*/
function _RC4($key, $text)
{
if ($this->last_rc4_key != $key) {
$k = str_repeat($key, 256/strlen($key)+1);
$rc4 = range(0,255);
$j = 0;
for ($i=0; $ilast_rc4_key = $key;
$this->last_rc4_key_c = $rc4;
} else {
$rc4 = $this->last_rc4_key_c;
}

$len = strlen($text);
$a = 0;
$b = 0;
$out = '';
for ($i=0; $i_md5_16($owner_pass);
$owner_RC4_key = substr($tmp,0,5);
return $this->_RC4($owner_RC4_key, $user_pass);
}

/**
* Compute U value
*/
function _Uvalue()
{
return $this->_RC4($this->encryption_key, $this->padding);
}

/**
* Compute encryption key
*/
function _generateencryptionkey($user_pass, $owner_pass, $protection)
{
// Pad passwords
$user_pass = substr($user_pass.$this->padding,0,32);
$owner_pass = substr($owner_pass.$this->padding,0,32);
// Compute O value
$this->Ovalue = $this->_Ovalue($user_pass,$owner_pass);
// Compute encyption key
$tmp = $this->_md5_16($user_pass.$this->Ovalue.chr($protection)."\xFF\xFF\xFF");
$this->encryption_key = substr($tmp,0,5);
// Compute U value
$this->Uvalue = $this->_Uvalue();
// Compute P value
$this->Pvalue = -(($protection^255)+1);
}
}

?>

Example
This example shows how to allow only printing.

SetProtection(array('print'));
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Arial');
$pdf->Write(10,'You can print me but not copy my text.');
$pdf->Output();
?>

Future Web Technologies


What can we expect from the next few years on the Web? Now we are happy into the current aera of the Web, commonly referred to as Web 2.0. Features of this phase of the Web include search, social networks, online media (music, video, etc), content aggregation and syndication (RSS), mashups (APIs), and much more. Currently the Web is still mostly accessed via a PC, but we are starting to see more Web excitement from mobile devices (e.g. iPhone) and television sets (e.g. XBox Live 360). I described here some of them in bellow.

When will the Semantic Web arrive? Some companies are actively trying to implement the Semantic Web. Semantic Web has been The Next Big Thing for a long time now. Indeed it’s become almost mythical, like Moby Dick. In a nutshell, the Semantic Web is about machines talking to machines. It’s about making the Web more ‘intelligent’ computers “analyzing all the data on the Web ‚the content, links, and transactions between people and computers.” So we are getting close, but we are probably a few years off still before the big promise of the Semantic Web is fulfilled.

Mobile Web is another Next Big Thing on slow boil. It’s already big in parts of Asia and Europe. In few years time there will be many more location-aware services available via mobile devices; such as getting personalized shopping offers as you walk through your local mall, or getting map directions while driving your car, or hooking up with your friends on a Friday night. But one of the main issues with Mobile Web has always been usability. So some mobile companies will probably be seen in few years time as the breakthrough Mobile Web device.

Major web sites are going to be transformed into web services – and will effectively expose their information to the world. Such transformations are never smooth – e.g. scalability is a big issue and legal aspects are never simple. But it is not a question of if web sites become web services, but when and how. Some web sites will offer their information via a REST API. The net effect will be that unstructured information will give way to structured information – paving the road to more intelligent computing.

This kind of technology has commercial applications today, as companies like Intelliseek are trying to provide users with business intelligence over the Web, including mining corporate Web sites for competitive intelligence information, such as lists of customer names. Some serious computer scientists, although cautious about the promise of the Semantic Web, are ultimately optimistic that it will be everything developers are hoping for — an online source for all of the knowledge that humanity has created in science, business and the arts.

References website
http://news.bbc.co.uk/1/hi/technology/3725884.stm
http://reviews.digitaltrends.com/guide/46-page-2/the-best-of-web-2-0
http://gigaom.com/2006/05/13/the-myth-reality-future-of-web-20/
http://www.itworld.com/Tech/4535/070709future/
http://www.technewsworld.com/story/31199.html

Everybody welcome to new Yahoo! Groups


Hi friends I am S.M. Saidur Rahman (Rana). Moderator of ‘cakephpexperts’ and ‘joomla_experts’ group at Yahoo! Groups, a free, easy-to-use email group service. Everybody welcome those both groups. I am inviting all to join those groups.

Join ‘cakephpexperts’ and ‘joomla_experts’ groups and made easy your programming life.
Click on the lines bellow to join groups.



Click to join cakephpexperts


Click to join joomla_experts

Create XL file from mysql table


As Experts requires today i have described here XL create class. Here we will show, How to create XL file from mysql tables? Its very simple for use. Just a simple mysql query and then config your database, a XL file will be created name as today date format. Next time we will show, How to create XL from XML file. That will come very soon i think.

XL Class file name iam_xls.php

<?php
class IAM_XLS {
/**
*
* @var string $xls_data Variable that holds the XLS File
* @access private
*/
var $xls_data;
var $crow = 0; // current row number
var $ccol = 0; // current column number
var $totalcol = 0; // total number of columns
var $header = 1; // 0=no header, 1=header line for xls table

/**
*
* @var string $xlsName Output Filename. No extension should be given as the class, as the class automatically attaches the XLS extension
* @access private
*/
var $xlsName;

/**
*
* @access public
* @param String $filename Output Filename. No extension should be given as the class, as the class automatically attaches the XLS extension
*/
function IAM_XLS($filename = 'spreadsheet')
{
$this->xls_data = "";
$this->xlsName = $filename;
$this->_excelStart();
}

/**
*
* @desc Writes a value to a cell in the in-memory file
* @access public
* @param int $xls_line Spreadsheet row (zero-based)
* @param int $xls_col Spreadsheet column (zero-based)
* @param mixed $value Cell value (String or Numeric)
*/
function WriteValue($xls_row, $xls_col, $value)
{
if (is_numeric($value))
$this->WriteCellNumber($xls_row, $xls_col, $value);
else
$this->WriteCellText($xls_row, $xls_col, $value);
}

/**
*
* @desc Generates a XLS File from an SQL Query (and outputs it to the browser)
* @access public
* @param String $query Query String
* @param String $db Name of the Database
* @param String $user User to Access the Database
* @param String $pass Password to Access the Database
* @param String $host Name of the Host holding the DB
*/
function WriteSQLDump($query, $db='', $user = '', $pass = '', $host = '')
{
$xls_line = 0;
$col = 0;

$link = $this->_db_connect($db, $user, $pass, $host);
if ($link) {
$result = @mysql_query($query, $link);
if (mysql_error() != "") {
$this->WriteValue(1, 0, "Ha ocurrido un error al consultar la base de datos: " . mysql_error());
// $this->OutputFile();
$this->savexl();
exit();
}

$lines = @mysql_num_rows($result);
$colums = mysql_num_fields($result);

for($e = 0; $e < $colums; $e++)
$this->WriteValue(0, $e, trim(ucwords(str_replace("_", " ", mysql_field_name($result, $e)))));

for($col = 0; $col < $colums; $col++) {
$col_name = mysql_field_name($result, $col);

for($i = 0; $i < $lines; $i++) {
$CellValue = mysql_result($result, $i, $col_name);

$xls_line = ($i + 1);

$this->WriteValue($xls_line, $col, $CellValue);
}
}
} else {
$this->WriteValue(1, 0, "Ha ocurrido un error al conectarse a la base de datos: " . mysql_error());
}
//$this->OutputFile();
$this->savexl();
}

/**
*
* @desc Closes the XLS File and Sends it to the browser
* @access public
*/
function OutputFile()
{
$this->_excelEnd();

$now = gmdate('D, d M Y H:i:s') . ' GMT';
$USER_BROWSER_AGENT = $this->_get_browser_type();

header('Content-Type: ' . $this->_get_mime_type());
header ("Content-Description: IAM Generated Excel File");
header('Expires: ' . $now);

if ($USER_BROWSER_AGENT == 'IE') {
header('Content-Disposition: attachment; filename="' . $this->xlsName . ".xls");
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
} else {
header('Content-Disposition: attachment; filename="' . $this->xlsName . ".xls");
header('Pragma: no-cache');
}

print ($this->xls_data);
}
function savexl(){
$this->_excelEnd();
if ( !stristr( $this->xlsName, ".xls" ) ) {
$this->xlsName .= ".xls";
}
$fp = fopen( $this->xlsName, "wb" );
if(fwrite( $fp, $this->xls_data ))
echo "File written successfully";
else echo "Can't write.";

fclose( $fp );
}

/**
*
* @desc Writes The XLS Header to the in-memory file
* @access private
*/
function _excelStart()
{
$this->xls_data = pack("vvvvvv", 0x809, 0x08, 0x00, 0x10, 0x0, 0x0);
}

/**
*
* @desc Writes The XLS End-of-File sequence to the in-memory file
* @access private
*/
function _excelEnd()
{
$this->xls_data .= pack("vv", 0x0A, 0x00);
if ( $this->header ) {
$this->Header();
}
}

/**
*
* @desc Writes a numeric value to a cell in the in-memory file
* @access public
* @param int $xls_row Spreadsheet row (zero-based)
* @param int $xls_col Spreadsheet column (zero-based)
* @param float $value Cell value
*/
function WriteCellNumber($xls_row, $xls_col, $value)
{
settype($value, 'float');
settype($row, 'integer');
settype($col, 'integer');

$this->xls_data .= pack("sssss", 0x0203, 14, $xls_row, $xls_col, 0x00);
$this->xls_data .= pack("d", $value);
}

/**
*
* @desc Writes a string value to a cell in the in-memory file
* @access public
* @param int $xls_row Spreadsheet row (zero-based)
* @param int $xls_col Spreadsheet column (zero-based)
* @param float $value Cell value
*/
/**
* Error handling for long strings, added by Robin Newman
*/
function WriteCellText($xls_row, $xls_col, $value)
{
settype($value, 'string');
settype($row, 'integer');
settype($col, 'integer');

$len = strlen($value);
if ($len > 255) {
$value = "#STRING TOO LONG:" . $len;
$len = strlen($value);
}
$this->xls_data .= pack("s*", 0x0204, 8 + $len, $xls_row, $xls_col, 0x00, $len);
$this->xls_data .= $value;
}

/**
*
* @desc Connects to a MYSQL Server and select the given Database
* @access private
* @param String $dbname Name of the Database
* @param String $user User to Access the Database
* @param String $password Password to Access the Database
* @param String $host Name of the Host holding the DB
* @return resource if connection was successful | FALSE
*/
function _db_connect($dbname = "test", $user = "root", $password = "", $host = "localhost")
{
$result = @mysql_pconnect($host, $user, $password);
if (!$result) { // If no connection, return 0
return false;
}

if (!@mysql_select_db($dbname)) { // If db not set, return 0
return false;
}
return $result;
}

/**
*
* @desc Define the client's browser type
* @access private
* @return String A String containing the Browser's type or brand
*/
function _get_browser_type()
{
$USER_BROWSER_AGENT = "";

if (ereg('OPERA(/| )([0-9].[0-9]{1,2})', strtoupper($_SERVER["HTTP_USER_AGENT"]), $log_version)) {
$USER_BROWSER_AGENT = 'OPERA';
} else if (ereg('MSIE ([0-9].[0-9]{1,2})', strtoupper($_SERVER["HTTP_USER_AGENT"]), $log_version)) {
$USER_BROWSER_AGENT = 'IE';
} else if (ereg('OMNIWEB/([0-9].[0-9]{1,2})', strtoupper($_SERVER["HTTP_USER_AGENT"]), $log_version)) {
$USER_BROWSER_AGENT = 'OMNIWEB';
} else if (ereg('MOZILLA/([0-9].[0-9]{1,2})', strtoupper($_SERVER["HTTP_USER_AGENT"]), $log_version)) {
$USER_BROWSER_AGENT = 'MOZILLA';
} else if (ereg('KONQUEROR/([0-9].[0-9]{1,2})', strtoupper($_SERVER["HTTP_USER_AGENT"]), $log_version)) {
$USER_BROWSER_AGENT = 'KONQUEROR';
} else {
$USER_BROWSER_AGENT = 'OTHER';
}

return $USER_BROWSER_AGENT;
}

/**
*
* @desc Define MIME-TYPE according to target Browser
* @access private
* @return String A string containing the MIME-TYPE String corresponding to the client's browser
*/
function _get_mime_type()
{
$USER_BROWSER_AGENT = $this->_get_browser_type();

$mime_type = ($USER_BROWSER_AGENT == 'IE' || $USER_BROWSER_AGENT == 'OPERA')
? 'application/octetstream'
: 'application/octet-stream';
return $mime_type;
}

function Header( $text="" ) {
if ( $text == "" ) {
$text = "This file was generated using PSXlsGen at ".date("D, d M Y H:i:s T");
}
if ( $this->totalcol < 1 ) {
$this->totalcol = 1;
}
$this->InsertText( $text );
$this->crow += 2;
$this->ccol = 0;
}

// insert a number, increment row,col automatically
function InsertText( $value )
{
if ( $this->ccol == $this->totalcol ) {
$this->ccol = 0;
$this->crow++;
}
$this->WriteText_pos( $this->crow, $this->ccol, &$value );
$this->ccol++;
return;
}

// write a label (text) into Row, Col
function WriteText_pos( $row, $col, $value )
{
$len = strlen( $value );
$this->xls_data .= $value;
return;
}
}

?>

And here an example file name example.php

<?php
require("iam_xls.php");

$query = "SELECT * FROM tablename";

$filename = date('Y-m-d');
$mid_excel = new IAM_XLS($filename);

$mid_excel->WriteSQLDump($query, 'test', 'root', '', 'localhost'); //query,dbname,username,password,servername
?>

Finally enjoy!