Posts

Showing posts with the label php

How to generate thumbnail from image and also apply watermark using php

Please refer below code for generate thumbnail from image and also apply watermark using php createThumbnail ( 'sign_in.png' ) ; function createThumbnail ( $filename ) { $path_to_thumbs_directory = 'thumbs/' ; $mimeType = mime_content_type ( $filename ) ; if ( $mimeType == "image/png" ) { $im = imagecreatefrompng ( $filename ) ; } else if ( $mimeType == 'image/gif' ) { $im = imagecreatefromgif ( $filename ) ; } else if ( $mimeType == 'image/jpg' || $mimeType == 'image/jpeg' ) { $im = imagecreatefromjpeg ( $filename ) ; } $ox = imagesx ( $im ) ; $oy = imagesy ( $im ) ; $nx = 256 ; $ny = 256 ; $nm = imagecreatetruecolor ( $nx , $ny ) ; imagecopyresized ( $nm , $im , 0 , 0 , 0 , 0 , $nx , $ny , $ox , $oy ) ; if ( ! file_exists ( $path_to_thumbs_directory )) { if ( ! mkdir ( $path_to_thumbs_directory )) { die ( "T...

How to make value as a key in multi dimensional array in php

For change key of multi dimensional array according to value of inner array just put below function into your script and use it.. if(!function_exists('array_keyBy')) { function array_keyBy($array , $keyBy) { if(!empty($array) && count($array) >0 ) { $tempArray = []; foreach($array as $key => $value) { if(!is_array($value)) { $value = (array) $value; } if(isset($value[$keyBy]) && $value[$keyBy]!='' && !is_array($value[$keyBy])) { $tempArray[$value[$keyBy]] = $value; } } $array = $tempArray; } return $array; } } For example: - I have an array as like below and i want to change key of multi dimensional array by value of name key. $person = array   (   array( 'name' => 'Romal', 'Age' => '34' ),   array( 'name' => '...

How Convert multi dimensional key value array to key value pair array in php

Today here i am sharing with you how to convert multi dimensional key value array to key value pair array. Below is example of multi dimensional array. Array ( [0] => Array ( [custom_key] => tax [custom_value] => 13 ) [1] => Array ( [custom_key] => currency [custom_value] => CAD ) [2] => Array ( [custom_key] => order_email [custom_value] => gobietesting@gmail.com,hiren@unoindia.co ) [3] => Array ( [custom_key] => timezone [custom_value] => America/New_York ) [4] => Array ( [custom_key] => is_ordering_available [custom_value] => 1 ) [5] => Array ( [custom_key] => store_number [custom_value] => 760 ) [6] => Array ( [custom_key] => is_sto...

How to Convert Number (amount) to Words (indian format) using php

For convert number or amount to indian word format copy and paste below code into your php file and call convertNumber function.. For example convertNumber(1000); function convertNumber($number,$prefix='',$suffix='', $uppercase = false)     {         $number = number_format($number,2);         list($num, $dec) = explode(".", $number);         $output = "";         if($num{0} == "-")         {             $output = "negative ";             $num = ltrim($num, "-");         }         else if($num{0} == "+")         {             $output = "positive ";           ...

How to create custom class or helpers in Laravel 5.*

For create a custom class or helpers or functions in laravel just follow below steps. I Created Libraries directory under app directory . Where i will put my all custom classes or helpers functions. Right now i create a Helpers Class under Libraries directory app/Libraries/Helpers.php <?php namespace App \ Libraries ; class Helpers { public static function test () { return "Test" ; } }   ?> Now I will create a new service provider for autoload all files under libraries directory. hit below command in terminal or create a new class LibrariesProvider under app/Providers directory. php artisan make : provider LibrariesProvider Now  my app/Providers/LibrariesProvide.php is as below: <?php namespace App \ Providers ; use Illuminate \ Support \ ServiceProvider ; class LibrariesProvider extends ServiceProvider { /** * Bootstrap the application services. * * @return void */ public function boot () { // } ...

Google map with php ajax request in bootstrap modal

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <script src="//code.jquery.com/jquery-1.12.0.min.js"></script> <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script> <div class="container business-setup">     <div class="row">         <div class="col-sm-12">             <h1 class="font-200">Business Setup</h1> <hr>         </div>     </div>        <form action="" class='form-horizontal'>     <div class="row business-profile">         <div class="col-md-9">             <div class="panel panel-default bmd-floating">           ...

How generate dynamic gradient effect in php

For generate dynamic gradient color in php just copy and paste below code into your file wherever you want to use.. <?php function random() {   return (float)rand()/(float)getrandmax(); } function getRandomArbitrary() {     $min = 0;     $max =0.5;     return random() * ($max - $min) + $min; }  $gradientSpeed = 0.002; function updateGradient() {     $min = 0; $max =0.5;     $colors =  array(   [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256),floor(getRandomArbitrary() * 256) ],   [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) ],   [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256) ],   [floor(getRandomArbitrary() * 256) , floor(getRandomArbitrary() * 256), floor(getRandomArbitrary() * 256) ],   [floor(getRandomArbitrary() * 256) , ...

How to take a screenshot or make a image of current screen using php and javascript with jquery or make a pdf file of current scrren

For create a image of current screen using javascript add below script into your file <script type="text/javascript"> function printDiv() {     jQuery('.year_box').remove(); // add your container id for capcture screen here i write "main_panel_body" for example     html2canvas([document.getElementById('main_panel_body')], {           onrendered: function(canvas)          {             var img = canvas.toDataURL();             jQuery('.overlay_box').show(); // calling ajax method for create image from binary data             $.post("save.php", {data: img}, function (file) {                 jQuery('.overlay_box').hide();  ...

How to use ajax without jquery with pure javascript

Here is a snippet code for ajax request.. var ajax = {}; ajax.x = function() {     if (typeof XMLHttpRequest !== 'undefined') {         return new XMLHttpRequest();     }     var versions = [         "MSXML2.XmlHttp.6.0",         "MSXML2.XmlHttp.5.0",          "MSXML2.XmlHttp.4.0",         "MSXML2.XmlHttp.3.0",          "MSXML2.XmlHttp.2.0",         "Microsoft.XmlHttp"     ];     var xhr;     for(var i = 0; i < versions.length; i++) {         try {             xhr = new ActiveXObject(versions[i]);          ...

How to upload image to another server like amazon etc using php CURL

For upload an image or any file to external server using php curl just refer below code. and change it according to your need. $profile_image_string = '';             if ( isset($_FILES['profile_image']) )             {                 $tmpfile = $_FILES['profile_image']['tmp_name'];                 $filename = basename($_FILES['profile_image']['name']);                 $filetype = $_FILES['profile_image']['type'];                 $org_image_string =curl_file_create($tmpfile,$filetype,$filename);             }     $ch = curl_init();         ...

How to add categories and tags option in custom post type in wordpress

How to add categories and tags option in custom post type. Just copy and paste below code into your theme's functions.php  function rj_register_post_type() { register_post_type('games',     array(     'description' => 'Game custom post type',         'show_ui' => true,         'exclude_from_search' => false,         'labels' => array(             'name' => 'Games',             'singular_name' => 'Game',             'add_new' => 'Add New Games',             'add_new_item' => 'Add New Game',             'edit' => 'Edit Games',             'edit_item' => 'Edit Game',...

Read all sub directories and check images or read image

For Read all images from the specific folders use below code $directories = glob($dir_path . '/*' , GLOB_ONLYDIR); if(count($directories)>0) {     foreach($directories as $sub_dir)     {         if(is_dir($sub_dir))         {                        //$images = glob($sub_dir.'/' . "*.jpg");            $images =  scandir($sub_dir.'/');             $scanned_directory = array_diff($images, array('..', '.'));                         foreach($scanned_directory as $image)             {      ...

How to add a custom taxonomy field in woocommerce product category or any other custom taxonomy in wordpress

For add a custom taxonomy  field in product category or any other custom taxonomy Add below code in functions.php file of your theme. function product_cat_add_video_field_rj() {         ?>     <div class="form-field">         <label for="term_meta[video_link]"><?php _e( 'Video Link', 'flatsome' ); ?></label>         <input type="text" name="term_meta[video_link]" id="term_meta[video_link]" value="">         <p class="description"><?php _e( 'Enter a Video Link','flatsome' ); ?></p>     </div> <?php } function product_cat_edit_video_field_rj($term) {     $t_id = $term->term_id;     $term_meta = get_option( "taxonomy_$t_id" ); ?>     <tr class="form-field">     <th scope="row" valign="top"><labe...