$imagePath = 'resource' . DIRECTORY_SEPARATOR . 'axel.png'; $svgPath = 'output' . DIRECTORY_SEPARATOR . 'axel.svg'; $imgContent = file_get_contents($imagePath); $img = imagecreatefromstring($imgContent); $imageSize = getimagesize($imagePath); $imgW = $imageSize[0]; $imgH = $imageSize[1]; $svg = SVGDocument::getInstance(); $svg->setWidth($imgW); $svg->setHeight($imgH); for ($x = 0; $x < $imgW; $x++) { for ($y = 0; $y < $imgH; $y++) { $rgb = imagecolorat($img, $x, $y); $color = imagecolorsforindex($img, $rgb); if ($color['alpha'] < 126) { $hex = RGBToHex($color['red'], $color['green'], $color['blue']); //$rect = SVGRect::getInstance( $x, $y, null, 1, 1, new SVGStyle( array( 'fill' => $hex ) ) ); //$d = "m $x,$y 1,0 0,1 -1,0 z"; $x1 = $x + 1; $y1 = $y + 1; $d = "M {$x},{$y} {$x},{$y1} {$x1},{$y1} {$x1},{$y} "; @($paths[$hex] .= $d); /* @$paths[$hex][$x . ',' . $y] = $x . ',' . $y; @$paths[$hex][$x . ',' . $y1] = $x . ',' . $y1; @$paths[$hex][$x1 . ',' . $y1] = $x1 . ',' . $y1; @$paths[$hex][$x1 . ',' . $y] = $x1 . ',' . $y; */ //M 25,20 25,21 26,21 26,20 z //$path = SVGPath::getInstance( $d, null, new SVGStyle( array( 'fill' => $hex ) ) ); //$svg->append( $path ); } }
if ($cvgavl == 'same') { unset($colorsunique[$key1]); } else { } } else { } } } } $wholearray = array_merge($wholearray, $colorsunique); //} } else { //foreach($bolan as $bolanin){ $arra = array(); $rbcn = explode(',', str_replace(')+++===colarr', '', str_replace('rgb(', '', $bolanin))); $hexty = RGBToHex($rbcn[0], $rbcn[1], $rbcn[2]); $arra[$hexty] = $hexty; //print_r($arra); $wholearray = array_merge($wholearray, $arra); //} } } //print_r($wholearray); /*die(); $colors_of_image = new ColorsOfImage( $_POST['imgpath'] ); $colors = $colors_of_image->getColorMap(); $lis = ''; $colorsunique = array_unique($colors); //echo '<pre>'; //print_r($colorsunique);
} } } } } if (strpos($value_type, 'Size')) { echo "- Size\n"; } if (strpos($value_type, 'Color')) { $color_type = $value->getColorDescription(); if ($color_type == 'rgb') { $color = $value->getColor(); $red = $color['r']->getSize(); $green = $color['g']->getSize(); $blue = $color['b']->getSize(); $hex_value = RGBToHex($red, $green, $blue); $colors[$rule_name] = $hex_value; if (!in_array($hex_value, $unique_colors)) { $unique_colors[] = $hex_value; } } if ($color_type == 'rgba') { $color = $value->getColor(); $rgba_values = array(); foreach ($color as $cc) { $rgba_values[] = $cc->getSize(); } $rgba = 'rgba(' . implode(', ', $rgba_values) . ')'; $colors[$rule_name] = $rgba; if (!in_array($rgba, $unique_colors)) { $unique_colors[] = $rgba;
/** * Compute the styles that should be applied for the * current element. * We start with the default style, and successively override * this with the current style, style set for the tag, classes * and inline styles. * */ function _htmltodocx_get_style($element, $state) { $style_sheet = $state['style_sheet']; // Get the default styles $phpword_style = $style_sheet['default']; // Update with the current style $current_style = $state['current_style']; // Remove uninheritable items: $inheritable_props = htmltodocx_inheritable_props(); foreach ($current_style as $property => $value) { if (!in_array($property, $inheritable_props)) { unset($current_style[$property]); } } $phpword_style = array_merge($phpword_style, $current_style); // Update with any styles defined by the element tag $tag_style = isset($style_sheet['elements'][$element->tag]) ? $style_sheet['elements'][$element->tag] : array(); $phpword_style = array_merge($phpword_style, $tag_style); // Find any classes defined for this element: $class_list = array(); if (!empty($element->class)) { $classes = explode(' ', $element->class); foreach ($classes as $class) { $class_list[] = trim($class); } } // Look for any style definitions for these classes: $classes_style = array(); if (!empty($class_list) && !empty($style_sheet['classes'])) { foreach ($style_sheet['classes'] as $class => $attributes) { if (in_array($class, $class_list)) { $classes_style = array_merge($classes_style, $attributes); } } } $phpword_style = array_merge($phpword_style, $classes_style); // Find any inline styles: $inline_style_list = array(); if (!empty($element->attr['style'])) { $inline_styles = explode(';', rtrim(rtrim($element->attr['style']), ';')); foreach ($inline_styles as $inline_style) { $style_pair = explode(':', $inline_style); $inline_style_list[] = trim($style_pair[0]) . ': ' . trim($style_pair[1]); } } // Look for style definitions of these inline styles: $inline_styles = array(); if (!empty($inline_style_list) && !empty($style_sheet['inline'])) { foreach ($style_sheet['inline'] as $inline_style => $attributes) { if (in_array($inline_style, $inline_style_list)) { $inline_styles = array_merge($inline_styles, $attributes); } } } $phpword_style = array_merge($phpword_style, $inline_styles); $new_style = array(); if ($element->attr && !empty($element->attr["style"])) { //解决文本颜色 $attr = $element->attr; $style = explode(";", $attr["style"]); foreach ($style as $k => $v) { $colorStyle = str_replace(" ", "", $v); if (mb_strpos($colorStyle, "color:") === 0) { $colorStr = str_replace("color:", "", $colorStyle); if (mb_strpos($colorStr, "rgb") !== false) { $new_style['color'] = RGBToHex($colorStr); } elseif (mb_strpos($colorStr, "#") !== false) { $new_style['color'] = str_replace("#", "", $colorStr); } } if (mb_strpos($colorStyle, "font-family:") === 0) { //解决文本字体 $colorStr = str_replace("font-family:", "", $colorStyle); $new_style['name'] = $colorStr; } if (mb_strpos($colorStyle, "font-size:") === 0) { //解决文本字体大小 $colorStr = str_replace("font-size:", "", $colorStyle); $new_style['size'] = str_replace("px", "", $colorStr); } if (mb_strpos($colorStyle, "line-through") !== false) { //解决文本加删除线 $new_style['strikethrough'] = true; } } } if (find_parent_strikethrough($element)) { //解决文本加删除线 $new_style['strikethrough'] = true; } $phpword_style = array_merge($phpword_style, $new_style); return $phpword_style; }
for ($i = 0; $i < sizeof($objects); $i++) { $firstName = $objects[$i][0]; $name = $objects[$i][1]; $country = $objects[$i][2]; //$color1 = getColor($firstName); //$color2 = getColor($name); //$color3 = getColor($country); //$hexColor = RGBToHex($color1, $color2, $color3); $hexColor = RGBToHex(225, 225, 225); //grey // $ctryColor = RGBToHex($color3, $color3, $color3); $length = strlen($firstName) + strlen($name); $str = $firstName . ' ' . $name . ' ' . $country . ' ' . implode("\n", $objects[$i][3]); echo '<div data-color="' . $hexColor . '" data-str="' . $str . '" data-width="' . $length . '" class="info">' . $str . '</div>'; //-------- years ---------// $years = $objects[$i][3]; for ($j = 0; $j < sizeof($years); $j++) { $year = $years[$j]; $rgbValue = getColor($year); $color = RGBToHex($rgbValue, $rgbValue, $rgbValue); echo '<div data-color="' . $color . '" data-str="' . $year . '" data-width="' . strlen($year) . '" class="edition">' . $year . '</div>'; } } ?> </div> <script src="jquery-1.11.3.min.js"></script> <script src="d3.min.js"></script> <script src="js/abstract_script.js"></script> </body> </html>