/** * protected function buildVariations * */ protected function buildVariations($buttonName) { $path = $this->builderFolder . $buttonName . '/'; $files = scandir($path . 'model/'); if (file_exists($path . 'passive.php')) { $addToPassive = '.' . sh_imagesBuilder::PASSIVE; } if (file_exists($path . 'selected.php')) { $isThereSelected = true; $addToPassive = '.' . sh_imagesBuilder::PASSIVE; } if (file_exists($path . 'active.php')) { $isThereActive = true; $addToPassive = '.' . sh_imagesBuilder::PASSIVE; } echo 'Successfully built variations : '; flush(); set_time_limit(0); $mtime = explode(" ", microtime()); $starttime = array_sum($mtime); for ($degree = 0; $degree <= 360; $degree += 20) { if (!is_dir($path . 'variations/' . $degree)) { mkdir($path . 'variations/' . $degree); } foreach ($files as $file) { $forcedSaturation = 0; if (array_pop(explode('.', $file)) == 'png') { $srcImage = $path . 'model/' . $file; $shortName = str_replace('.png', '', $file); $destImage = $path . 'variations/' . $degree . '/' . $shortName . $addToPassive . '.png'; if ($degree == 360) { $forcedSaturation = -100; } sh_colors::setHueToImage($srcImage, $destImage, $degree, $forcedSaturation); if ($isThereSelected) { sh_colors::setHueToImage($srcImage, $path . 'variations/' . $degree . '/' . $shortName . '.' . sh_imagesBuilder::SELECTED . '.png', $degree, $forcedSaturation, -10); } if ($isThereActive) { sh_colors::setHueToImage($srcImage, $path . 'variations/' . $degree . '/' . $shortName . '.' . sh_imagesBuilder::ACTIVE . '.png', $degree, $forcedSaturation, 10); } } } echo $separator . $degree; $separator = ' - '; flush(); } $mtime = explode(" ", microtime()); echo '<br />Build time : ' . (array_sum($mtime) - $starttime) . 's.<br />'; echo 'Press F5 to reload the form properly.<hr />'; return true; }
protected function variation_change_folder($sourceFolder, $destinationFolder, $variation, $transposedValue) { if (!is_dir($destinationFolder)) { mkdir($destinationFolder); } $files = scandir($sourceFolder); foreach ($files as $file) { if (substr($file, -4) == '.png') { sh_colors::setHueToImage($sourceFolder . $file, $destinationFolder . $file, $variation, 0, $transposedValue); } elseif (substr($file, 0, 1) != '.' && is_dir($sourceFolder . $file)) { $this->variation_change_folder($sourceFolder . $file . '/', $destinationFolder . $file . '/', $variation, $transposedValue); } } }
public static function getPalette($source) { $model = imagecreatefrompng($source); $colors = array(); $loops = array('reallyDark', 'dark', 'normal', 'shiny', 'reallyShiny'); for ($x = 0; $x < 370; $x += 10) { foreach ($loops as $factor => $name) { $rgb = imagecolorat($model, $x, 5 + $factor * 10); $color = imagecolorsforindex($model, $rgb); $rgbCol = array('R' => $color['red'], 'G' => $color['green'], 'B' => $color['blue']); $out = sh_colors::RGBToHSV($rgbCol); $out['R'] = $color['red']; $out['G'] = $color['green']; $out['B'] = $color['blue']; $out['alpha'] = $color['alpha']; $hex = '#'; $hex .= str_pad(dechex($color['red']), 2, '0', STR_PAD_LEFT); $hex .= str_pad(dechex($color['green']), 2, '0', STR_PAD_LEFT); $hex .= str_pad(dechex($color['blue']), 2, '0', STR_PAD_LEFT); $out['hex'] = $hex; $colors[$x][$name] = $out; } } $colors[370] = $colors[360]; return $colors; }
protected function createPreview($font, $height) { if (file_exists(SH_FONTS_FOLDER . $font)) { $font = SH_FONTS_FOLDER . $font; } elseif (file_exists($this->linker->site->templateFolder . 'fonts/' . $font)) { $font = $this->linker->site->templateFolder . 'fonts/' . $font; } else { die('The font ' . $font . ' was not found!'); } $text = self::PREVIEW_TEXT; $image = SH_TEMPIMAGES_FOLDER . md5(microtime()); $imageBuilder = $this->linker->imagesBuilder; list($size) = $imageBuilder->getFontSizeByTextHeight(sh_fonts::FONT_THUMB_TEXT, $font, $height); $dims = $imageBuilder->getDimensions($text, $size, $font); $imageBuilder->createImageWithBackground($image, sh_colors::RGBStringToRGBArray('FFFFFF'), $dims['width'], $dims['height']); $imageBuilder->addText($text, $image, $dims['left'], $dims['top'], $font, $size, '000000'); $contentType = mime_content_type($image); header('Content-type: ' . $contentType); readfile($image); unlink($image); return true; }
/** * protected function buildVariations * */ protected function buildVariations($variationFolder, $templateName = '', $baseVariation = '') { flush(); set_time_limit(0); echo '<html><head> <title>Shopsailors - Variations builder</title> <link rel="shortcut icon" href="' . $this->linker->favicon->getPath() . '"></link>'; echo '</head><body>'; echo '<div style="font-weight:bold">Building the variations for the template ' . $templateName . '</div>'; echo 'Base variation : ' . $baseVariation; $filesList = $this->getFilesList($variationFolder . 'default/'); $hexColors = array('#cb0000', '#cb4200', '#cb8700', '#cbcb00', '#87cb00', '#42cb00', '#00cb00', '#00cb43', '#00cb86', '#00cbcb', '#0086cb', '#0042cb', '#0000cb', '#4200cb', '#8700cb', '#cb00cb', '#cb0087', '#cb0043', '#cbcbcb'); if (is_array($filesList)) { $total = 0; for ($degree = 0; $degree <= 360; $degree += 20) { $this->helper->emptyDir($variationFolder . $degree); if (!is_dir($variationFolder . $degree)) { mkdir($variationFolder . $degree); } } echo '<style>table td{background-color:white;text-align:center;font-size:70%;padding:2px;}</style>'; echo '<table cellpadding="0" cellspacing="1" style="background-color:black;"><tr><td>#</td>'; foreach ($filesList as $file) { echo '<td style="background-color:orange;">' . str_replace('.png', '', $file['name']) . '</td>'; } echo '<td>Time</td><td>Total</td>'; echo '</tr>'; flush(); for ($degree = 0; $degree <= 360; $degree += 20) { $mtime = explode(" ", microtime()); $starttime = array_sum($mtime); $allowedExts = array('png', 'jpg', 'jpeg'); echo '<tr>'; echo '<td style="background-color:' . $hexColors[$degree / 20] . '">' . $degree . '</td> '; foreach ($filesList as $file) { $ext = strtolower(array_pop(explode('.', $file['name']))); if (in_array($ext, $allowedExts)) { if (!is_dir($variationFolder . $degree . '/' . $file['folder'] . '/')) { mkdir($variationFolder . $degree . '/' . $file['folder'] . '/', 0777, true); } $destImage = $variationFolder . $degree . '/' . $file['folder'] . '/' . $file['name']; $destImage = str_replace('//', '/', $destImage); $srcImage = $variationFolder . 'default/' . $file['folder'] . '/' . $file['name']; $srcImage = str_replace('//', '/', $srcImage); $mtime2 = microtime(true); flush(); if ($degree != 360) { sh_colors::setHueToImage($srcImage, $destImage, $degree); } else { sh_colors::setHueToImage($srcImage, $destImage, 0, -100); } echo '<td>' . substr(microtime(true) - $mtime2, 0, 5) . 's</td>'; flush(); } } $mtime = explode(" ", microtime()); $thisTime = array_sum($mtime) - $starttime; $total += $thisTime; echo '<td>' . substr($thisTime, 0, 5) . 's</td><td>' . substr($total, 0, 5) . 's</td>'; echo '</tr>'; flush(); } echo '</table>'; echo 'All variations were built successfully in ' . floor($total / 60) . " minutes and " . $total % 60 . ' seconds<br />'; echo 'Press F5 to continue (and press OK if needed).'; echo '</body></html>'; } }
protected function getPalette($source) { if (isset($this->palettes[basename($source)])) { return basename($source); } if (file_exists($this->unpackFolder . $source)) { $source = $this->unpackFolder . $source; } $this->palettes[basename($source)] = sh_colors::getPalette($source); return basename($source); }
public function addText($text, $image, $x, $y, $font, $fontSize, $fontColor, $transparency = 0, $addReflect = false) { $srcImage = imagecreatefrompng($image); $width = imagesx($srcImage); $box = $this->getDimensions($text, $fontSize, $font); $textHeight = $box['height']; imagesavealpha($srcImage, true); imagealphablending($srcImage, false); $color = sh_colors::RGBStringToRGBArray($fontColor); $r = 120; $color['R']; $g = rand(0, 255); $color['G']; $b = rand(0, 255); $color['B']; $newColor = imagecolorallocatealpha($srcImage, $r, $g, $b, $transparency); if ($addReflect == true) { $reflect = imagecreatetruecolor($width, $textHeight / 2); $textColor2 = imagecolorallocatealpha($reflect, $r, $g, $b, 0); $transparentColor2 = imagecolorallocatealpha($reflect, 0, 0, 0, 127); imagefill($reflect, 0, 0, $transparentColor2); imagecolortransparent($reflect, $transparentColor2); // writes the text imagettftext($reflect, $fontSize, 0, $x, $textHeight / 2, $textColor2, $font, $text); $cpt = 0; $open = false; // Gets the pixels that are colored in the first line for ($a = 1; $a < $width + 1; $a++) { for ($b = 1; $b < $textHeight / 2 - 1; $b++) { $color = imagecolorat($reflect, $a, $b); $colorrgb = imagecolorsforindex($reflect, $color); if ($colorrgb['alpha'] < 45) { $trans = $colorrgb['alpha'] + 127 - $b * 1.5 / ($textHeight / 2) * 45; if ($trans < 127) { $tempColor = imagecolorallocatealpha($srcImage, $colorrgb['red'], $colorrgb['green'], $colorrgb['blue'], $trans); imagesetpixel($srcImage, $a, $y + $textHeight / 2 - $b, $tempColor); } } } } imageDestroy($reflect); } // writes the text imagettftext($srcImage, $fontSize, 0, $x, $y, $newColor, $font, $text); imagepng($srcImage, $image); imageDestroy($srcImage); return true; }