$im = imagecreatefrompng($imgdir); // $white = imagecolorallocate($bm, 255, 255, 255); imagefilter($im, IMG_FILTER_COLORIZE, $red, $green, $blue); // imagecolortransparent($bm, $white); ob_start(); imagepng($im); $changed_file = base64_encode(ob_get_contents()); ob_end_clean(); imagepng($im, $imgdir . "?" . $query); $base64 = 'data:image/png' . ';base64,' . $changed_file; imagedestroy($im); echo $base64; // echo $imgtype; } else { if ($ext === 'eps') { $im = imagecreatefromstring(base64_decode(transparent($imgdir, $imgtype))); imagepng($im, "/var/www/mch/env/html5_configurator/img/design/{$post['sessionid']}-{$date}-test_layer.png"); $tempimg_path = "/var/www/mch/env/html5_configurator/img/design/{$post['sessionid']}-{$date}-test_layer.png"; $imgdir = $tempimg_path; imagedestroy($im); $im = new Imagick(); $im->setResolution(100, 100); $im->readImage($imgdir); $im->setImageFormat("png"); $extln = strlen($ext); $dir = substr($imgdir, 0, strlen($imgdir) - $extln); $imgdir = $dir . "png"; // echo $imgdir; // die(); $im->writeImages($imgdir . "?" . $query, true); $im->destroy();
function exWrapper($a) { $line_1 = $a['line_1']; $line_2 = $a['line_2']; $line_3 = $a['line_3']; $line_4 = $a['line_4']; $line_1_font = $a['line_1_font']; $line_2_font = $a['line_2_font']; $line_3_font = $a['line_3_font']; $line_4_font = $a['line_4_font']; $line_1_size = $a['line_1_size']; $line_2_size = $a['line_2_size']; $line_3_size = $a['line_3_size']; $line_4_size = $a['line_4_size']; $line_1_x = $a['line_1_x']; $line_2_x = $a['line_2_x']; $line_3_x = $a['line_3_x']; $line_4_x = $a['line_4_x']; $line_1_y = $a['line_1_y']; $line_2_y = $a['line_2_y']; $line_3_y = $a['line_3_y']; $line_4_y = $a['line_4_y']; $red = $a['red']; $green = $a['green']; $blue = $a['blue']; $red_text = $a['red_text']; $green_text = $a['green_text']; $blue_text = $a['blue_text']; $base = new \Imagick('/var/www/mch' . $a['base']); $draw = new \ImagickDraw(); $textColor = "rgb({$red_text}, {$green_text}, {$blue_text})"; if (isset($a['layer_top']) && $a['layer_top'] != "") { $layout = new \Imagick(); $layout_x = $a['layer_top_x']; $layout_y = $a['layer_top_y']; if ($a['image_uploaded'] != true) { $tempimg = '/var/www/mch/' . $a['layer_top']; $im = imagecreatefromstring(base64_decode(transparent($tempimg))); imagepng($im, "test_layer.png"); $tempimg_path = "test_layer.png"; $blob = base64_decode(convert($tempimg_path, $red, $green, $blue)); $layout->readImageBlob($blob); $layout->setImageFormat('png'); } else { $layout->readImage($img); } } if ($line_1 != "" || $line_2 != "" || $line_3 != "" || $line_4 != "") { // $line_1_x = $line_1_x + 25; $line_2_x = $line_2_x + 25; $line_3_x = $line_3_x + 25; $line_4_x = $line_4_x + 25; $line_1_x = $line_1_x < 0 ? 0 : $line_1_x; //$line_1_x = ($line_1_x > 198 ? 198: $line_1_x); $line_2_x = $line_2_x < 0 ? 0 : $line_2_x; //$line_2_x = ($line_2_x > 198 ? 198: $line_2_x); $line_3_x = $line_3_x < 0 ? 0 : $line_3_x; //$line_3_x = ($line_3_x > 198 ? 198: $line_3_x); $line_4_x = $line_4_x < 0 ? 0 : $line_4_x; //$line_4_x = ($line_4_x > 198 ? 198: $line_4_x); // $temp = new Imagick(); // $temp->newImage($w, $h); $draw->setFont($line_1_font); $draw->setFontSize($line_1_size); $draw->setFontWeight(700); $draw->setFillColor($textColor); $base->annotateImage($draw, $line_1_x, $line_1_y, 0, $line_1); $draw->setFont($line_2_font); $draw->setFontSize($line_2_size); $draw->setFontWeight(700); $draw->setFillColor($textColor); $base->annotateImage($draw, $line_2_x, $line_2_y, 0, $line_2); $draw->setFont($line_3_font); $draw->setFontSize($line_3_size); $draw->setFontWeight(700); $draw->setFillColor($textColor); $base->annotateImage($draw, $line_3_x, $line_3_y, 0, $line_3); $draw->setFont($line_4_font); $draw->setFontSize($line_4_size); $draw->setFontWeight(700); $draw->setFillColor($textColor); $base->annotateImage($draw, $line_4_x, $line_4_y, 0, $line_4); } echo "line 1x : " . $line_1_x . " line 2x : " . $line_2_x . " line 3x : " . $line_3_x . " line 4x: " . $line_4_x; // $img = '/var/www/mch'.$a['layout']; // $size = getimagesize($a['img']); // $h = $size[1]; // $w = $size[0]; $h = 100; $w = 100; $x = $layout_x; $y = $layout_y; // echo $x." "; // echo $y; if ($x < 134) { $x = 134; } if ($x > 186) { $x = 186; } if ($y < 27) { $y = 27; } if ($y > 84) { $y = 84; } $date = date('Y_m_d_H_i_s'); if (isset($a['layer_top']) && $a['layer_top'] != "") { $layout->resizeImage($w, $h, Imagick::FILTER_LANCZOS, 1); $base->compositeImage($layout, Imagick::COMPOSITE_DISSOLVE, $x, $y); } $bar = $base->writeImage('/var/www/mch/public/test_wrapper.png'); $base->destroy(); if ($bar) { $barpath = "test_wrapper.png"; // echo "x-axis : ".$x." y-axis : ".$y; echo "<img src='{$barpath}'>"; return $bar; } else { return false; } }
$im->readImage($imgdir); $im->setImageFormat("png"); $extln = strlen($ext); $dir = substr($imgdir, 0, strlen($imgdir) - $extln); $imgdir = $dir . "png"; // echo $imgdir; // die(); $im->writeImages($imgdir, true); $bm = imagecreatefrompng($imgdir); list($width, $height) = getimagesize($imgdir); $new_width = $width; $new_height = $height; // $white = imagecolorallocate($bm, 255, 255, 255); // imagefilter($bm, IMG_FILTER_GRAYSCALE); // imagecolortransparent($bm, $white); imagepng(transparent($bm, $new_width, $new_height), $imgdir); imagedestroy($bm); } } } } } } $uri = substr($imgdir, 13, strlen($imgdir) - 1); $ref = ""; $ref = explode("?", $_SERVER['HTTP_REFERER']); echo "{$uri}"; //header("Location:$ref[0]?files=$uri"); } } function transparent($im, $new_width, $new_height)