/** * 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); } } }
/** * 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 addLayer($destination, $layerParams, $imageParams, $palette, $state, $width, $height, $destX, $destY) { // we create a temp image $tempImage = imagecreatetruecolor($width, $height); imagesavealpha($tempImage, true); imagealphablending($tempImage, false); $transp = imagecolorallocatealpha($tempImage, 0, 0, 0, 127); imagefill($tempImage, 0, 0, $transp); $variationName = $this->linker->site->variation . '_' . $this->linker->site->saturation; $saturations = array('reallyDark' => -50, 'dark' => -25, 'normal' => 0, 'shiny' => 25, 'reallyShiny' => 50); $hsvValue = $saturations[$this->linker->site->saturation]; // we loop in all the images parts, to fill an array foreach ($imageParams as $partId => $part) { if (preg_match('`([0-9]+)_([0-9]+)(_x)?(_y)?`', $partId, $matches)) { $folder = dirname($part); $image = baseName($part); // We check if the variation exists $src = $folder . '/variations/' . $variationName . '/' . $image; if (!file_exists($this->builtImageRoot . $src)) { if (!is_dir(dirname($this->builtImageRoot . $src))) { $this->helper->createDir(dirname($this->builtImageRoot . $src)); } if ($this->linker->site->variation < 370) { $hue = $this->linker->site->variation; $opacity = 127; if ($palette == 'none') { copy($this->builtImageRoot . $part, $this->builtImageRoot . $src); } else { // We check if we have to use a custom palette if ($palette != 'default') { // We do, so we will read the hue in it (present in $this->allParams) //$palette = $this->allParams['palettes'][$layerParams['palette'][$state]]; $col = $palette[$this->linker->site->variation][$this->linker->site->saturation]; $hue = $col['H']; $opacity = 127 - $col['alpha']; } sh_colors::setHueToImage($this->builtImageRoot . $part, $this->builtImageRoot . $src, $hue, 0, $hsvValue, $opacity / 127); } } else { if ($palette == 'none') { copy($this->builtImageRoot . $src, $this->builtImageRoot . $part); } else { // Greyscale sh_colors::setHueToImage(SH_TEMPIMAGES_FOLDER . 'greyscale.png', $this->builtImageRoot . $src, 0, 0, $hsvValue, $opacity / 127); sh_colors::setGreyScaleToImage($this->builtImageRoot . $part, SH_TEMPIMAGES_FOLDER . 'greyscale.png'); } } } $parts[$matches[1]][$matches[2]] = array('src' => $src, 'stretchX' => $matches[3] == '_x', 'stretchY' => $matches[4] == '_y'); if ($matches[3] == '_x') { $columnsToStretch[$matches[2]] = true; } if ($matches[4] == '_y') { $linesToStretch[$matches[1]] = true; } } else { if ($partId == 'minimalWidth') { $minimimalWidth = $part; } elseif ($partId == 'minimalHeight') { $minimimalHeight = $part; } } } // Calculating the number of pixels to add in width $numberOfStretchableX = count($columnsToStretch); $stretchXSize = (int) (($width - $minimimalWidth) / $numberOfStretchableX); $numberOfPixelsToAddX = ($width - $minimimalWidth) % $numberOfStretchableX; $numberOfStretchableY = count($linesToStretch); $stretchYSize = (int) (($height - $minimimalHeight) / $numberOfStretchableY); $numberOfPixelsToAddY = ($height - $minimimalHeight) % $numberOfStretchableY; $top = 0; $tempNumberOfPixelsToAddY = $numberOfPixelsToAddY; foreach ($parts as $lineNumber => $line) { $left = 0; $tempNumberOfPixelsToAddX = $numberOfPixelsToAddX; foreach ($line as $cellNumber => $cell) { // We get the image $srcImage = imagecreatefrompng($this->builtImageRoot . $cell['src']); // We get the image size $srcWidth = imagesx($srcImage); $srcHeight = imagesy($srcImage); if ($cell['stretchX']) { if ($tempNumberOfPixelsToAddX > 0) { $imageDestX = $stretchXSize + 1; $tempNumberOfPixelsToAddX--; } else { $imageDestX = $stretchXSize; } } else { $imageDestX = $srcWidth; } $totalWidth += $imageDestX; if ($cell['stretchY']) { if ($tempNumberOfPixelsToAddY > 0) { $imageDestY = $stretchYSize + 1; $tempNumberOfPixelsToAddY--; } else { $imageDestY = $stretchYSize; } } else { $imageDestY = $srcHeight; } // We copy the image imagecopyresampled($tempImage, $srcImage, $destX + $left, $destY + $top, 0, 0, $imageDestX, $imageDestY, $srcWidth, $srcHeight); imagedestroy($srcImage); $left += $imageDestX; } $totalWidth = 0; $top += $imageDestY; } // We then copy the content of the temp image on the destination image imagealphablending($destination, true); imagecopy($destination, $tempImage, 0, 0, 0, 0, $width, $height); imagealphablending($destination, false); return $destination; }