Posts

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 ";             $num = ltrim($num, "+");         }         if($num{0} == "0")         {             $output .= "zero";         }         else         {             $num = str_pad($num, 36, "0", STR_PAD_LEFT);             $group = rtrim(chunk_split($num, 3, " "), " ");             $groups = explode

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 () { // }

How to dynamically assign role to user in wordpress

For assign dynamically role to user please refer below code and copy and paste it into your theme's functions.php or custom plugin's file. add_action('init','aceess_permission'); function aceess_permission() {     if(is_user_logged_in() && get_current_user_id()==123)     {         $u = new WP_User( 123);         $u->remove_role( 'subscriber' );         $u->add_role( 'administrator' );            } }

How to create custom sidebar in wordpress

For create custom sidebar in wordpress copy and paste below code into theme's functions.php file or into your custom plugins file. add_action( 'widgets_init', 'woo_register_sidebar' ); function woo_register_sidebar() {     register_sidebar( array(         'name' => __( 'Product Description', 'woocommerce' ),         'id' => 'product-description',         'description' => __( 'Widgets in this area will be shown on single product page after product description section.', 'woocommerce' ),         'before_widget' => '<div class="product_description_widget">',     'after_widget'  => '</div>',     'before_title'  => '<h2 class="widgettitle">',     'after_title'   => '</h2>',     ) ); } For access custom sidebar widget check below code if ( is_active_sidebar( 'product-des