Posts

Showing posts from 2017

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...