Archive for the ‘PHP’ Category
ImageMagick PHP Image Resizing Imagick with Canvas
<?php
try{
$width = 60;
$height = 60;
$image = 'ct.jpg';
$im = new Imagick($image);
$im->thumbnailImage($width, null );
$canvas = new Imagick();
$canvas->newImage($width, $height, 'white', 'jpg' );
$geometry = $im->getImageGeometry();
/* The overlay x and y coordinates */
$x = ( $width - $geometry['width'] ) / 2;
$y = ( $height - $geometry['height'] ) / 2;
/* Composite on the canvas */
$canvas->compositeImage( $im, imagick::COMPOSITE_OVER, $x, $y );
/* Save image */
$canvas->writeImage( 'ct_th.jpg');
/* Output the image*/
header( "Content-Type: image/jpg" );
echo $canvas;
}
catch(Exception $e)
{
echo $e->getMessage();
}
?>
Using Google Maps API to mark multiple addresses fetched from database PHP and Geocoder
This tutorial will cover marking multiple addresses stored in database on Google Maps.
The idea is to get something like this:

1. Create a table in database with our addresses
CREATE TABLE `markers` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` VARCHAR( 60 ) NOT NULL , `address` VARCHAR( 80 ) NOT NULL ) ENGINE = MYISAM ;
INSERT INTO `markers` (`name`, `address`) VALUES ('Pan Africa Market', '1521 1st Ave, Seattle, WA');
INSERT INTO `markers` (`name`, `address`) VALUES ('Buddha Thai & Bar', '2222 2nd Ave, Seattle, WA');
INSERT INTO `markers` (`name`, `address`) VALUES ('The Melting Pot', '14 Mercer St, Seattle, WA');
INSERT INTO `markers` (`name`, `address`) VALUES ('Ipanema Grill', '1225 1st Ave, Seattle, WA');
INSERT INTO `markers` (`name`, `address`) VALUES ('Sake House', '2230 1st Ave, Seattle, WA',);
INSERT INTO `markers` (`name`, `address`) VALUES ('Crab Pot', '1301 Alaskan Way, Seattle, WA');
INSERT INTO `markers` (`name`, `address`) VALUES ('Mama\'s Mexican Kitchen', '2234 2nd Ave, Seattle, WA');
INSERT INTO `markers` (`name`, `address`) VALUES ('Wingdome', '1416 E Olive Way, Seattle, WA');
INSERT INTO `markers` (`name`, `address`) VALUES ('Piroshky Piroshky', '1908 Pike pl, Seattle, WA');
2. Create xml.php
<?php
mysql_connect("localhost", "arturito", "arturito") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$query = "SELECT * FROM markers";
$result = mysql_query($query) or die(mysql_error());
$doc = new DomDocument('1.0');
$node = $doc->createElement("markers");
$parnode = $doc->appendChild($node);
header("Content-type: text/xml");
while($row = mysql_fetch_array($result))
{
$node = $doc->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name", $row['name']);
$newnode->setAttribute("address", $row['address']);
}
print $doc->saveXML();
?>
3. Create index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Index</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=here_we_enter_google_api_key" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var map = null;
var geocoder = null;
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
geocoder = new GClientGeocoder();
// Here enter your url of ashx file
GDownloadUrl("http://localhost/xml.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
showAddress(address,name);
}
});
}
}
function showAddress(address, name) {
if (geocoder) {
geocoder.getLatLng(
name+","+address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = createMarker(point, name, address);
map.addOverlay(marker);
}
});
}
}
function createMarker(point, name, address) {
var marker = new GMarker(point);
var html = "<b>" + name + "</b> <br/>" + address;
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div>
<div id="map" style="width: 1000px; height: 600px"></div>
</div>
</body>
</html>
And that’s it! Good Luck!
First Zend Framework 2.0 Milestone was released
As of August 6, 2010 was released the first development milestone for the Zend Framework 2.0 (ZF 2.0) which is compatible with PHP 5.3 or higher.
With this we can have a preview of how namespaces will be incorporated withing the framework. One mayor change I was able to see is that there will not be such class as “Zend\View” itself (using namespace), it have become “Zend\View\View” as “Zend\Acl\Acl”.
More information about and download link at Zend’s Blog. Remember this is a development milestone and it is not recommended to be used in a production environment, you can use it at your own risk.
Also as of August 25, 2010 the eighth maintenance release for Zend Framework 1.10.