Saturday, 9 January 2016

Rotate Image using Jquery & PHP

Many Library available for rotating the image object.
But, here we are rotating the image object using Jquery, Ajax and PHP.
Here using PHP GD library for rotating the image object.
There are many options to rotate the image object.
But, here we using simple method.
Note: In this example We used jpeg format Image. If you have to use png or gif then you have to use other function for create image. For example : for jpeg => imagecreatefromjpeg($filename), imagejpeg($rotate,”test_rot.jpeg”); You have to change underline text according to image format.
PHP function for rotating the image object : imagerotate ==> Rotate an image with a given angle
Syntax :
resource imagerotate ( resource $image , float $angle , int $bgd_color [, int $ignore_transparent = 0 ] )

Where,
image : An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
angle : Rotation angle, in degrees. The rotation angle is interpreted as the number of degrees to rotate the image anticlockwise.
bgd_color : Specifies the color of the uncovered zone after the rotation
ignore_transparent : If set and non-zero, transparent colors are ignored (otherwise kept).
More info : http://php.net/manual/en/function.imagerotate.php
Simple Example :
          php_img_rotate.php :
<html>
<head>
<title>Simple Example : Rotating Images using PHP,Jquery & AJAX</title>
<!–  Include Jquery Lib. –>
<script type=”text/javascript” src=”http://code.jquery.com/jquery-2.1.4.min.js”></script >
</head>
<body>
<!– Image which We have to rotate –>
<img id=”img_” src=”test_rot.jpeg”>
<!– There are controllers which used for rotate the images Anti Clock or Clock wise  –>
<div>
<div class=”anti” style=”cursor: pointer”>Rotate Anti Clock Wise</div>
<div class=”clock” style=”cursor: pointer”>Rotate Clock Wise</div>
</div>
<!– Jquery Ajax Function for anti clock & Clock wise Rotate –>
<script type=”text/javascript”>
$(“.anti”).click(function()
{
$.ajax({
type:’POST’,
url:’ajax_img_rotate.php’,
data:”wh=anti”,
success:function(data)
{
//here we use this code for override the image. We use ?  because If we not write that then your image is not refesh and
// If you refesh whole page then it will be changed., So, we write ? .
document.getElementById(“img_”).src = document.getElementById(“img_”).src+ “?”;
}
});
})
$(“.clock”).click(function()
{
$.ajax({
type:’POST’,
url:’php_img_rotate.php’,
data:”wh=clock”,
success:function(data)
{
document.getElementById(“img_”).src = document.getElementById(“img_”).src+ “?”;
}
});
})
</script>
</body>
</html>
Now,
ajax_img_rotate.php
<?php
// File name. We can pass the image name for more dynamic
$filename = ‘test_rot.jpeg’;
if($_POST[‘wh’]==”clock”)  //Check Its clock wise rotate request or anti clock wise
{
$degrees = 360-90; // If clock wise then Degree is calculated here.
}else if($_POST[‘wh’]==”anti”)
{
$degrees = 90; /// If anti clock wise then Degree is calculated here.
}
// Load
//This function for jpeg format only if you have to use png or gif then you have to use different functions as per the image format
$source = imagecreatefromjpeg($filename);
// Rotate
$rotate = imagerotate($source, $degrees, 0);
// Output
//This function for jpeg format only if you have to use png or gif then you have to use different functions as per the image format
imagejpeg($rotate,”test_rot.jpeg”);
// Free the memory
imagedestroy($source);
imagedestroy($rotate);
?>

Thursday, 10 January 2013

how to set default timezone in php?

<?php

date_default_timezone_set('Europe/London');

echo date('Y-m-d H:i:s');

?>

how to fetch all supported timezones in PHP?

<?php

$timezone_offsets = array();

foreach(timezone_identifiers_list() as $timezone_identifier)

{

$date_time_zone = new DateTimeZone($timezone_identifier);

$date_time = new DateTime('now', $date_time_zone);

$timezone_offsets[$timezone_identifier] = $date_time_zone->getOffset($date_time);

}

echo "<pre>";

print_r($timezone_offsets);

?>

Wednesday, 31 October 2012

how to refresh particular div tag content without reloading page using jquery?

// Note : First include jquery.js file.....
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load_div').load('load.php').fadeIn("slow");
}, 100000); // refresh every 10000 milliseconds
</script>

//index.php

<div id="load_div">
</div>

//load.php

In this page you can write your code.
like load randam user,image etc....

Tuesday, 23 October 2012

How to pass data from one domain to another domain(cross domain) using json?‏

//Javascript code

<script type="text/javascript">

$(document).ready(function()
{

var surl =  "http://www.example.com/json.php";

email_id=document.getElementById("email").value;

$.ajax({
url: surl,
data: {email:email_id},
dataType: "jsonp",
jsonp : "callback",
jsonpCallback: "jsonpcallback"
});
});

function jsonpcallback(rtndata)
{
document.getElementById("disp_data").innerHTML=rtndata.message;
}

</script>

//json.php file code

<?php

$display="<b>HI Json</b>";

$display.="<p>HI This is testing json.</p>";

$rtnjsonobj->message = $display;

echo $_GET['callback']. '('. json_encode($rtnjsonobj) . ')';

?>

Tuesday, 16 October 2012

error page using htaccess file

first create .htaccess  file and save it.

then write below code

ErrorDocument 404 /404.html

 

here

404 means when page not found then it occurs

404.html means that page which you want to display.