Example #1
0
$size = Array(imagesx($src),imagesy($src));

$out = imagecreatetruecolor($size[0],$size[1]) or die('Problem In Creating image');

imagealphablending($out, false);
imagesavealpha($out, true);

// scan image pixels
for ($x = 0; $x < imagesx($src); $x++) {
	for ($y = 0; $y < imagesy($src); $y++) {
		$src_pix = imagecolorat($src,$x,$y);

		$ycbcr = rgb_to_ycbcr_array($src_pix);
      $o = colorclose($ycbcr[1], $ycbcr[2], $cb, $cr, $a, $b);

      $rgb1 = rgb_to_array($src_pix);
      imagesetpixel($out, $x, $y, imagecolorallocatealpha($out, $rgb1[0], $rgb1[1], $rgb1[2], 127 - ($o*127) ));
	}
}

imagepng($out,'content/images/'.$output) or die('Problem saving output image');
imagedestroy($out);

// split rgb to components
function rgb_to_array($rgb) 
{
	$a[0] = ($rgb >> 16) & 0xFF;
   $a[1] = ($rgb >> 8) & 0xFF;
   $a[2] = $rgb & 0xFF;
         
   return $a;
Example #2
0
            $csx . "," . $csy . "," . $cex . "," . $cey;
            "<br />";
        }
    }
    $white = 1;
}
$srr = '';
for ($ino = 0; $ino < 6; $ino++) {
    $src = imagecreatefromJPEG('ltr' . $ino . '.jpg') or die('Problem with source');
    $out = ImageCreateTrueColor(imagesx($src), imagesy($src)) or die('Problem In Creating image');
    $string = '';
    // scan image pixels
    for ($x = 0; $x < imagesx($src); $x++) {
        for ($y = 0; $y < imagesy($src); $y++) {
            $src_pix = imagecolorat($src, $x, $y);
            $src_pix_array = rgb_to_array($src_pix);
            if ($src_pix_array[0] > 100 && $src_pix_array[1] > 100 && $src_pix_array[2] > 100) {
                $string .= '0';
            } else {
                $string .= '1';
            }
        }
    }
    $string .= '1';
    //echo $string."<br />";  //Uncomment this when building database
    for ($i = 0; $i < count($letterlist); $i++) {
        if (strcmp($letterlist[$i]['hash'], $string) == 0) {
            $srr .= $letterlist[$i]['letter'];
            break;
        }
    }
Example #3
0
function save_julep_image($julep_post)
{
    //print_r($_POST);
    $julep_text_info = json_decode(stripslashes($_POST['julep_text_info']));
    $julep_image_source = urldecode($_POST['julep_image_source']);
    $julep_post_id = $_POST['julep_post_id'];
    if (isset($julep_text_info) && !empty($julep_text_info)) {
        $julep_image_path = wp_get_attachment_image_src($julep_post_id, 'full');
        $actual_image_url = $julep_image_path[0];
        $julep_image_source = get_home_path() . str_replace(get_site_url() . '/', '', $julep_image_path[0]);
        $file_type_info = wp_check_filetype($julep_image_source);
        $julep_metadata = wp_get_attachment_metadata($julep_post_id);
        /*$julep_file_contents = file_get_contents($julep_image_source);
        		if(isset($julep_metadata['sizes']) && !empty($julep_metadata['sizes']))
        		{
        			$julep_mime_type = $julep_metadata['sizes']['thumbnail']['mime-type'];
        			$julep_img_ext 	= str_replace('image/', '', $julep_metadata['sizes']['thumbnail']['mime-type']);
        			
        			$julep_content_img = "rate-bar-bg-" . $i . ".jpg";
        			$imageContent = file_get_contents("http://www.lafourchette.com/p-3.3.0/default/" . $imageName);
        			file_put_contents($imageName, $imageContent);
        		}
        		
        		print_r($julep_metadata);
        		exit;*/
        $imagecreatefrom = 'imagecreatefrom' . str_replace('image/', '', $file_type_info['type']);
        if (isset($file_type_info) && !empty($file_type_info)) {
            $responses = array();
            foreach ($julep_text_info as $julep_key => $julep_text_single) {
                header('Content-type: ' . $file_type_info['type']);
                $julep_image = $imagecreatefrom($julep_image_source);
                $julep_font_family = isset($julep_text_single[8]) && $julep_text_single[8] != '' ? $julep_text_single[8] : 'arial';
                $julep_font_size = isset($julep_text_single[9]) && $julep_text_single[9] != '' ? $julep_text_single[9] : 12;
                $julep_font_weight = isset($julep_text_single[10]) && $julep_text_single[10] != '' ? $julep_text_single[10] : 'normal';
                $julep_font_style = isset($julep_text_single[11]) && $julep_text_single[11] != '' ? $julep_text_single[11] : 'normal';
                $julep_text_decoration = isset($julep_text_single[12]) && $julep_text_single[12] != '' ? $julep_text_single[12] : 'none';
                $julep_text_color = isset($julep_text_single[13]) && $julep_text_single[13] != '' ? $julep_text_single[13] : '#ffffff';
                $julep_rgb = rgb_to_array($julep_text_color);
                $julep_text_color = imagecolorallocate($julep_image, $julep_rgb[0], $julep_rgb[1], $julep_rgb[2]);
                if ((strtolower($julep_font_weight) == 'bold' || $julep_font_weight == 700) && strtolower($julep_font_style) == 'italic') {
                    $julep_ttf = 'Bold_Italic.ttf';
                } elseif (strtolower($julep_font_weight) == 'bold' || $julep_font_weight == 700) {
                    $julep_ttf = 'Bold.ttf';
                } elseif (strtolower($julep_font_style) == 'italic') {
                    $julep_ttf = 'Italic.ttf';
                } else {
                    $julep_ttf = 'Regular.ttf';
                }
                $julep_font_path = 'fonts/' . strtolower($julep_font_family) . '/' . $julep_ttf;
                $julep_font_size = px_to_point($julep_font_size);
                $julep_text = str_replace('<br>', "\n", $julep_text_single[2]);
                //echo $julep_text;
                $coords = offset_to_xy_coords($julep_text_single[4], $julep_text_single[5], $julep_text_single[6], $julep_text_single[7], $julep_metadata['height'], $julep_metadata['width']);
                //print_r($coords);
                $julep_text_single[3] = css_rotaion_to_angle($julep_text_single[3]);
                $julep_response = imagettftext($julep_image, $julep_font_size, (int) $julep_text_single[3], $coords['x'], $coords['y'], $julep_text_color, $julep_font_path, $julep_text);
                //print_r($julep_response);
                $image_type = str_replace('/', '', $file_type_info['type']);
                $image_type($julep_image, $julep_image_source);
                if (isset($julep_metadata['sizes']) && !empty($julep_metadata['sizes'])) {
                    $upload_path = pathinfo($julep_image_source);
                    foreach ($julep_metadata['sizes'] as $s_key => $size) {
                        $image = wp_get_image_editor($julep_image_source);
                        if (!is_wp_error($image)) {
                            $image->resize($size['width'], $size['height'], true);
                            $image->save($upload_path['dirname'] . '/' . $size['file']);
                        }
                    }
                }
                imagedestroy($julep_image);
                if (isset($julep_response) && !empty($julep_response)) {
                    $responses[] = $julep_response;
                } else {
                    echo json_encode(array('result' => 'error', 'message' => "Error occured while saving text changes.", 'actual_image_url' => $actual_image_url));
                }
            }
            if (!isset($responses) || empty($responses)) {
                echo json_encode(array('result' => 'error', 'message' => "No text saved.", 'actual_image_url' => $actual_image_url));
            } else {
                echo json_encode(array('result' => 'success', 'message' => "Changes saved.", 'actual_image_url' => $actual_image_url));
            }
        } else {
            echo json_encode(array('result' => 'error', 'message' => "No text to be saved.", 'actual_image_url' => $actual_image_url));
        }
    } else {
        echo json_encode(array('result' => 'error', 'message' => "No text saved.", 'actual_image_url' => $actual_image_url));
    }
    exit;
}