Saturday, September 22, 2012

Water mark in PHP


Processing with image in PHP, Adding watermark is very help full. Add Image Watermark with original image is also help to protect our images here is my solution to Add Water Mark in PHP


Prepare an transparent image with exact same size of the original image. Transparent PNG with Text by overlap original image to create a final watermark added image.

<?php
// Original Image Path
$image= "images/original_image.jpg";  

header("Content-type: image/jpeg");
header("Content-Disposition: inline; filename=$image");

switch (TRUE) {
case stristr($image,'jpg') :
$photoImage = ImageCreateFromJPEG("$image");
break;
case stristr($image,'gif') :
$photoImage = ImageCreateFromGIF("$image");
break;
case stristr($image,'png') :
$photoImage = ImageCreateFromPNG("$image");
break;
}

ImageAlphaBlending($photoImage, true); 

// Same Size PNG Watermark Image with Transparency
$logoImage = ImageCreateFromPNG("watermark_image.png"); 
$logoW = ImageSX($logoImage); 
$logoH = ImageSY($logoImage); 

// were you see the two 1's this is the offset from the top-left hand corner!
ImageCopy($photoImage, $logoImage, 1, 1, 0, 0, $logoW, $logoH); 

imagejpeg($photoImage);
// if you want to save add the following line
imagejpeg($photoImage,"images/final.jpg");

ImageDestroy($photoImage); 
ImageDestroy($logoImage); 

?>




Friday, September 21, 2012

Convert Text Area to Array PHP



Processing multiple records through Text Area, We may need to convert that text area values into array from every line of text in that TextArea. here is my solution to "Convert TextArea to Array"



<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Text Area to Array</title>
</head>
<body>

<?php
// Check Form Submission
if(isset($_POST['submit']))
{
 // Capture cities text into variable
 $text = ucwords($_POST['cities']);
 // Replace entry new line with Comma(,)
 $cities = preg_replace("~\s*[\r\n]+~", ', ', $text);
 // Explode by Comma(,) and trim if any white spaces with array_map
 $cities = array_map('trim',explode(",",$cities));
 // final output as array
 echo "<pre>";
 print_r($cities);
 echo "</pre>";
}


?>

<form action="" method="post">
  <h2>Convert Text Area to Array</h2>
  <p>Enter each city every line<br />
    <textarea name="cities" cols="50" rows="10" id="keywords"></textarea>
    <br />
    <br />
    
    <input name="submit" type="submit" value="Submit Cities" id="submit" />
  </p>
</form>
</body>
</html>



Download This Script     Live Demo