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.

 

 

Thursday, 6 September 2012

How to convert timestamp to date in MYSQL with where clause?

SELECT * , DATE( FROM_UNIXTIME( `time_stamp` ) ) AS sBdat
FROM phpfox_feed
WHERE DATE( FROM_UNIXTIME( `time_stamp` ) ) = '2012-09-05'

How to convert timestamp to date in MYSQL?

MYSQL:

SELECT DATE( FROM_UNIXTIME( `time_stamp` ) ) AS sBdat FROM users

 

OUTPUT:

2012-09-06

Tuesday, 24 July 2012

how to check element visibility in jquery?

example of element exists and it’s not visible


<div id="test">
<div id="test_1" style="display:none">
Hello World!
</div>
</div>


jQuery code:
if ($('#test_1:visible').length > 0)
{
alert('the element is visible');
}
else
{
alert('the element is not visible');
}


Tuesday, 3 July 2012

how to replace & or special characters in javascript?

//if  value of catnm='art & jewllery';

//then i want need to replace "&".

//because when i will try to post data using jquery then jquery know this is query string.....so i want to need  to replace "&"  using "URL ENCODED CHARACTERS"

//so,see below example

var catnm=document.getElementById('catnm').value;

var cat_re=catnm.replace('&','%26');

OUTPUT 

In Javascript alert box  : art %26 jewllery

In html format(in web browser )  : art & jewllery

Please refer below website for URL Encode Characters

http://www.degraeve.com/reference/urlencoding.php

http://www.w3schools.com/tags/ref_urlencode.asp

Friday, 27 April 2012

how to validate multiple select box with jquery?

$("#form").validate({
rules:{
"select_esp[]": "required"
},
messages:{
"select_esp[]": "Select this"
}
});

 

Saturday, 14 April 2012

How to enable/disable element in Javascript

If u want to enable or disable any HTML element using javascript in asp.net/php u can use the following code,

document.getelementbyid('nm').disabled='disabled' ;


and the below code will enable the element,

document.getelementbyid('nm').disabled='';

Tuesday, 3 April 2012

how to make captcha in php?

Captcha Code:

<?php
session_start();

$num='';

$string = "abcdefghijklmnopqrstuvwxyz0123456789";
for($i=0;$i<7;$i++){
$num1=rand(0,35);
$num .= $string{$num1};
}

$_SESSION["num1"]=$num;

$img=imagecreatefrompng('captcha.png');
$color=imagecolorallocate($img,255,255,255);
$color1=imagecolorallocate($img,0,0,0);
imagestring($img,9,10,3,$num,30);
$fontsize=20;
$fontcolor = imagecolorallocate($img, 0, 0, 0);
$x = 0;
$y = $fontsize;

header('Content-type : image/png');
imagepng($img);
imagedestroy($img);

?>

How to use in php?

<img id="cap" style="margin-left: 15px;" src="comman/captcha.php" alt="" />

How to refresh captcha?

Call the below function  onclick

<script >
function captcha()
{
document.getElementById('cap').src = document.getElementById('cap').src+ '?';
}
</script>

Save as captcha.png file

Monday, 2 April 2012

how to check path of ffmpeg or mencoder in linux in php?

<?php
$output = shell_exec('whereis ffmpeg');
echo "<pre>".$output."</pre>";
echo "";

$output = shell_exec('whereis mencoder');
echo "<pre>".$output."</pre>";
echo "";
?>

Output in browser :

Monday, 26 March 2012

How to launch jQuery Fancybox on page load?

//first include fancybox javascript file and jquery javascript file.

<script type="text/javascript">

jQuery(document).ready(function() {
$("a#various2").trigger('click');
});
</script>

Friday, 23 March 2012

how to remove any character using javascript?

I am removing only " - (dash), . (dot), (space) in this exmple.

function dotrm(cit)
{
var cl=cit.length;
var ch=cit;
for(l=0;l<=cl;l++)
{
if(cit[l] == '.' || cit[l] == ' ' || cit[l]=='-')
{
ch=cit.replace(cit[l],'');
}
}
document.getElementById("city").value=ch;
}

Saturday, 17 March 2012

how to backup mysql database using php?

<?php
$backfile="a.sql";
$command="mysqldump  -u root test>$backfile";//
system($command);
?>

Friday, 16 March 2012

how to validate password allow space in middle of string

function spc(str)
{
var l=str.length;//check length of string
for(var i=0;i<l;i++)
{
if(str[0]==' ' || str[str.length-1]==' ')//check first & last character of password
{
document.getElementById("spa_error").innerHTML='Space key cannot be used for the first or last character of your password';
}else
{
document.getElementById("spa_error").innerHTML='';
}
}
}