Advertisement
Guest User

Untitled

a guest
Aug 16th, 2011
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 5.60 KB | None | 0 0
  1. <?php
  2. // user uploads file and it moves to server
  3. move_uploaded_file ($_FILES['Image']['tmp_name'], "/sites/".$_FILES['Image']['name']) or die ('Could not upload');
  4. ?>
  5.  
  6.  
  7. <?php
  8. // create image path
  9. $img = imagecreatefromjpeg("/sites/".$_FILES['Image']['name']);
  10. ?>
  11.  
  12.  
  13. <?php
  14. //pixelate function
  15. //if($img && imagefilter($img,IMG_FILTER_PIXELATE,4))
  16.  
  17. imagejpeg($img,'image.jpg',100);
  18. ?>
  19.  
  20. <?php
  21.  
  22. // resize image
  23.  
  24.     $output_width =30;
  25.     $output_height=50;
  26.     $xytotal = $output_width*$output_height;
  27.  
  28.     $path = '/sites/image.jpg';
  29.     $size_arr = getimagesize($path);
  30.     if ($size_arr[2]==IMAGETYPE_GIF)
  31.         $image = imagecreatefromgif($path);
  32.     else if ($size_arr[2]==IMAGETYPE_JPEG)
  33.         $image = imagecreatefromjpeg($path);
  34.     else if ($size_arr[2]==IMAGETYPE_PNG)
  35.         $image = imagecreatefrompng($path);
  36.     else
  37.         die_default_image();
  38.  
  39.     $tmpname = tempnam( sys_get_temp_dir() , "phptmp");
  40.  
  41.     resize_image($tmpname, $image, $size_arr, $output_width, $output_height);
  42.  
  43.     $img = imagecreatefromjpeg($tmpname);
  44.     imagejpeg($img,'image.jpg',100);
  45.    
  46.     unlink( $tmpname );
  47.    
  48. // loop to populate rgb values into css spans
  49.    
  50.     $imagew = imagesx($img);
  51.     $imageh = imagesy($img);
  52.    
  53. echo "Image (w,h): ($imagew, $imageh)<br/>";
  54.    
  55.     $x = 0;
  56.     $y = 0;
  57.    
  58.     $counter = 0;
  59.    
  60.     for ($y = 0; $y < $imageh; $y++) {
  61.     for ($x = 0; $x < $imagew; $x++) {
  62.             $rgb = imagecolorat($img, $x, $y);
  63.             $r = ($rgb >> 16) & 0xFF;
  64.             $g = ($rgb >> 8) & 0xFF;
  65.             $b = $rgb & 0xFF;
  66.    
  67.         $original_r = $r;
  68.         $original_g = $g;
  69.         $original_b = $b;
  70.    
  71.             if($r%16 !=0){ //if remainder of $r value is !=0 then increment $r value by 1 while $counter < 8
  72.                 do{
  73.                     $r++;
  74.                     $counter++;
  75.                 } //end do
  76.                 while($counter < 8);
  77.             }
  78.             elseif($r%16 != 0){
  79.                 $counter = 0;
  80.                 do{
  81.                     $r -=1;
  82.                     $counter++;
  83.                 } while($counter < 8);
  84.             }
  85.            
  86.             $counter = 0; // reset counter value
  87.            
  88.             if($g%16 !=0){ //if remainder of $g value is !=0 then increment $r value by 1 while $counter < 8
  89.                 do{
  90.                     $g++;
  91.                     $counter++;
  92.                 } while($counter < 8);
  93.             }
  94.             elseif($g%16 != 0){
  95.                 $counter = 0;
  96.                 do{
  97.                     $g -=1;
  98.                     $counter++;
  99.                 } while($counter < 8);
  100.             }
  101.             $counter = 0; // reset counter value
  102.  
  103.             if($b%16 !=0){ //if remainder of $b value is !=0 then increment $r value by 1 while $counter < 8
  104.                 do{
  105.                     $b++;
  106.                     $counter++;
  107.                 } while($counter < 8);
  108.                
  109.             }
  110.             elseif($b%16 != 0){
  111.                 $counter = 0;
  112.                 do{
  113.                     $b -=1;
  114.                     $counter++;
  115.                 } while($counter < 8);
  116.             }
  117.            
  118. // placing $rgb values into arrays to be shown
  119.             $css_color = str_pad(dechex($r), 2, "0", STR_PAD_LEFT).str_pad(dechex($g), 2, "0", STR_PAD_LEFT).str_pad(dechex($b), 2, "0", STR_PAD_LEFT); //convert rgb into css
  120.            
  121.             //echo "[($x,$y) ($r,$g,$b)]";
  122.             echo '<span style="width: 5px; height: 5px; background-color:#'.$css_color.'" >'.$x. ' ' .$y.' '.$css_color.' '.$r.' '.$g.' '.$b.'</span>';
  123.             echo '<br />';
  124.            
  125.             $css_color_original = str_pad(dechex($r), 2, "0", STR_PAD_LEFT).str_pad(dechex($g), 2, "0", STR_PAD_LEFT).str_pad(dechex($b), 2, "0", STR_PAD_LEFT); // original css color values
  126.            
  127.             echo '<span style="width: 5px; height: 5px; background-color:#'.$css_color_original.'">'.$x. ' ' .$y.' '.$css_color_original.' '.$original_r.' '.$original_g.' '.$original_b.'<br /><br /></span';
  128.             echo '<br />';
  129.     }
  130.     }
  131.    
  132. ?>
  133.  
  134.  
  135. <script type="text/javascript" src="jquery-1.6.2.js"></script>
  136. <script src="formatted_colors.js" type="text/javascript" charset="utf-8"></script>
  137. <script type="text/javascript">
  138.  
  139. //iterate through pixels and match rounded color to array in formatted_colors.js
  140.  
  141. <div class="rounded_color" hex="<?php $css_color ?>" xy="<?php $x.$y ?>"</div>
  142. <div id="<?php $x.$y ?>"></div>
  143.  
  144. $(document).ready(function() {
  145.  
  146.     $(".rounded_color").each(function(){
  147.             var google_color = getColor($(this).attr("hex"));
  148.             $('#'+$(this).attr("id")).html(google_color);
  149.             $('#'+$(this).attr("id")).css('background-color:', google_color);
  150.     })
  151.    
  152.    
  153. // get name of color function from formatted_colors.js
  154.  
  155. function getColor(target_color){
  156.     if (colors[target_color] == undefined) { // not found
  157.       return "no match";
  158.     } else {
  159.       return colors[target_color];
  160.     }
  161.   } // end getColor function
  162.  
  163.  
  164. )} // end ready function
  165.  
  166. </script>
  167.  
  168. <?php
  169.  
  170. //image resizing functions
  171. function die_default_image()
  172. {
  173.     //43byte 1x1 transparent pixel gif
  174.     header("content-type: image/gif");
  175.     echo base64_decode("R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
  176. }
  177.  
  178. function resize_image($thumbname, $image, $size_arr, $max_width, $max_height)//maintain aspect ratio
  179. {
  180.     $width  = $max_width;
  181.     $height = $max_height;
  182.     list($width_orig, $height_orig, $img_type) = $size_arr;
  183.     $ratio_orig = $width_orig/$height_orig;
  184.  
  185.     if ($width/$height > $ratio_orig) {
  186.        $width = floor($height*$ratio_orig);
  187.     } else {
  188.        $height = floor($width/$ratio_orig);
  189.     }
  190.  
  191.     // Resample
  192.     $tempimg = imagecreatetruecolor($width, $height);
  193.     imagecopyresampled($tempimg, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
  194.     imagejpeg($tempimg, $thumbname, 80);
  195. }
  196.  
  197. if ( !function_exists('sys_get_temp_dir')) {
  198.   function sys_get_temp_dir() {
  199.     if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); }
  200.     if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); }
  201.     if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); }
  202.     $tempfile=tempnam(uniqid(rand(),TRUE),'');
  203.     if (file_exists($tempfile)) {
  204.     unlink($tempfile);
  205.     return realpath(dirname($tempfile));
  206.     }
  207.   }
  208. }
  209. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement