1
0

Get gallery images generating properly. It was always setting the color to black so it wouldn't show up properly.

This commit is contained in:
Tim Almdal 2010-08-09 12:32:43 -07:00
parent 9b92859a60
commit 9d3c9edc95
5 changed files with 222 additions and 196 deletions

View File

@ -158,11 +158,12 @@ class Admin_Themeroller_Controller extends Admin_Controller {
->error_messages("required", t("You must enter a theme display name"));
if (!empty($theme_name)) {
$name_field->value($theme_name);
$display_name->value(ucwords(t("%name theme", array("name" => $theme_name))));
$display_name->value(ucwords(t("%name theme", array("name" => str_replace("-", " ", $theme_name)))));
$original_name->hidden("original")->value(Session::instance()->get("themeroller_name"));
}
$form_group->textarea("description")->label(t("Description"))
->id("g-description")
->value(t("A generated theme based on the ui themeroller '%name' styling", array("name" => $theme_name)))
->rules("required")
->error_messages("required", t("You must enter a theme description name"));
$form_group->submit("")->value(t("Create"));

View File

@ -80,6 +80,10 @@ class themeroller {
}
}
}
if (empty($parameters["colors"]["bgColorOverlay"])) {
$parameters["colors"]["bgColorOverlay"] = $parameters["colors"]["bgColorDefault"];
// @todo go find the .ui-widget-overlay { background: #aaaaaa
}
$parameters["js"] = $is_admin ? glob(MODPATH . "themeroller/data/js/admin_*.js") :
glob(MODPATH . "themeroller/data/js/site_*.js");
$parameters["standard_css"] = glob(MODPATH . "themeroller/data/css/*.css");
@ -105,7 +109,7 @@ class themeroller {
}
static function generate_image($mask_file, $color, $target_dir, $replace_with="") {
$output = $target_dir . str_replace("mask", $replace_with, basename($mask_file));
$output = $target_dir . str_replace("_mask", $replace_with, basename($mask_file));
$mask = imagecreatefrompng($mask_file);
$image = imagecreatetruecolor(imagesx($mask), imagesy($mask));
$icon_color = self::_rgb(hexdec($color));
@ -113,16 +117,16 @@ class themeroller {
$transparent = imagecolorallocatealpha($image,
$icon_color['red'], $icon_color['green'], $icon_color['blue'], 127);
imagefill($image, 0, 0, $transparent);
imagefilter($mask, IMG_FILTER_EDGEDETECT);
for ($y=0; $y < imagesy($mask); $y++) {
for ($x=0; $x < imagesx($mask); $x++) {
$pixel_color = imagecolorsforindex($mask, imagecolorat($mask, $x, $y));
$mask_color = self::_grayscale_pixel($pixel_color);
$mask_alpha = 127 - (floor($mask_color["red"] / 2) * (1 - ($pixel_color["alpha"] / 127)));
//$mask_alpha = 127 - (floor($mask_color["red"] / 2) * (1 - ($pixel_color["alpha"] / 127)));
$mask_alpha = 127 - floor($mask_color["red"] * 127 / 256);
$new_color = imagecolorallocatealpha($image,
$icon_color['red'], $icon_color['green'], $icon_color['blue'], $mask_alpha);
imagesetpixel($image, $x, $y, $new_color);
imagesetpixel($image, $x, $y, $new_color);
}
}
@ -131,6 +135,8 @@ class themeroller {
imagepng($image, $output);
imagedestroy($image);
imagedestroy($mask);
return $output;
}
static function generate_thumbnail($base, $parts, $target) {
@ -156,11 +162,6 @@ class themeroller {
imagedestroy($image_part);
}
//$new_width = 200;
//$new_height = floor($height * $new_width / $width);
//$resized = imagecreatetruecolor($new_width, $new_height);
//imagecopyresampled($resized, $image, 0, 0, 0, 0,$new_width, $new_height, $width, $height);
imagesavealpha($image, true);
imagealphablending($image, false);
imagepng($image, $target);

View File

@ -24,197 +24,225 @@ class themeroller_task_Core {
}
static function create_theme($task) {
$mode = $task->get("mode", "init");
$start = microtime(true);
$theme_name = $task->get("theme_name");
$is_admin = $task->get("is_admin", false);
$theme_path = THEMEPATH . "$theme_name/";
$parameters = $task->get("parameters");
$completed = $task->get("completed", 0);
switch ($mode) {
case "init":
$views = glob(MODPATH . "themeroller/data/views/*.html.php");
$task->set("mode", "create_directory");
$parameters = themeroller::get_theme_parameters($task->get("original_name"),
$task->get("path"),
$is_admin);
$task->set("total_activites",
7 // number of directories to create
+ 3 // screen.css, theme.info, thumbnail
+ count($parameters["standard_css"]) // number of standard css to copy
+ count($parameters["views"]) // number of views to copy
+ count($parameters["js"]) // number of javascript files to copy
+ count($parameters["masks"]) // number of images to generate
+ count($parameters["icons"]) // number of icon images to generate
+ count($parameters["css_files"]) // number of css files
+ count($parameters["images"])); // number of image files to copy
$task->status = t("Starting up");
break;
case "create_directory":
$completed = $task->get("completed");
foreach (array("", "css", "css/themeroller", "css/themeroller/images", "images",
"js", "views") as $dir) {
$path = "{$theme_path}$dir";
$completed++;
if (!file_exists($path)) {
mkdir($path);
chmod($path, 0755);
}
try {
$mode = $task->get("mode", "init");
$start = microtime(true);
$theme_name = $task->get("theme_name");
$is_admin = $task->get("is_admin", false);
$theme_path = THEMEPATH . "$theme_name/";
$parameters = Cache::instance()->get("create_theme_cache:{$task->id}");
if ($parameters) {
$parameters = unserialize($parameters);
}
$task->status = t("Directory created");
$task->set("mode", "copy_views");
break;
case "copy_views":
$task->status = t("Copying views");
while (!empty($parameters["views"]) && microtime(true) - $start < 1.5) {
$view = array_shift($parameters["views"]);
$target = "{$theme_path}views/" . basename($view);
if (!file_exists($target)) {
copy($view, $target);
$completed = $task->get("completed", 0);
switch ($mode) {
case "init":
$task->log(t("Starting theme '%theme' creation", array("theme" => $task->get("display_name"))));
$task->set("mode", "create_directory");
$parameters = themeroller::get_theme_parameters($task->get("original_name"),
$task->get("path"),
$is_admin);
$task->set("total_activites",
7 // number of directories to create
+ 3 // screen.css, theme.info, thumbnail
+ count($parameters["standard_css"]) // number of standard css to copy
+ count($parameters["views"]) // number of views to copy
+ count($parameters["js"]) // number of javascript files to copy
+ count($parameters["masks"]) // number of images to generate
+ count($parameters["icons"]) // number of icon images to generate
+ count($parameters["css_files"]) // number of css files
+ count($parameters["images"])); // number of image files to copy
$task->status = t("Starting up");
break;
case "create_directory":
$completed = $task->get("completed");
foreach (array("", "css", "css/themeroller", "css/themeroller/images", "images",
"js", "views") as $dir) {
$path = "{$theme_path}$dir";
$completed++;
if (!file_exists($path)) {
mkdir($path);
chmod($path, 0755);
$task->log(t("Created directory: %path", array("path" => $path)));
}
}
$completed++;
}
if (empty($parameters["views"])){
$task->status = t("Views copied");
$task->set("mode", "copy_themeroller_images");
}
break;
case "copy_themeroller_images":
$task->status = t("Copying themeroller images");
while (!empty($parameters["images"]) && microtime(true) - $start < 1.5) {
$image = array_shift($parameters["images"]);
$target = "{$theme_path}css/themeroller/images/" . basename($image);
if (!file_exists($target)) {
copy($image, $target);
$task->status = t("Directories created");
$task->set("mode", "copy_views");
break;
case "copy_views":
$task->status = t("Copying views");
while (!empty($parameters["views"]) && microtime(true) - $start < 1.5) {
$view = array_shift($parameters["views"]);
$target = "{$theme_path}views/" . basename($view);
if (!file_exists($target)) {
copy($view, $target);
$task->log(t("Copied view: %path", array("path" => basename($view))));
}
$completed++;
}
$completed++;
}
if (empty($parameters["views"])){
$task->status = t("Themeroller images copied");
$task->set("mode", "copy_css");
}
break;
case "copy_css":
$task->status = t("Copying themeroller css");
$target = "{$theme_path}css/themeroller/ui.base.css";
copy($parameters["css_files"][0], $target);
$completed++;
$task->status = t("Themeroller css copied");
$task->set("mode", "generate_images");
break;
case "generate_images":
$task->status = t("Generating gallery images");
$target_dir = "{$theme_path}images/";
$colors = $task->get("colors");
$image_color = $colors["iconColorHover"];
while (!empty($parameters["masks"]) && microtime(true) - $start < 1.5) {
$mask = array_shift($parameters["masks"]);
themeroller::generate_image($mask, $image_color, $target_dir);
$completed++;
}
if (empty($parameters["masks"])) {
$task->set("mode", "generate_icons");
$task->status = t("Gallery images generated");
}
break;
case "generate_icons":
$task->status = t("Generating icons");
$target_dir = "{$theme_path}css/themeroller/images/";
while (!empty($parameters["icons"]) && microtime(true) - $start < 1.5) {
$color = array_shift($parameters["icons"]);
themeroller::generate_image($parameters["icon_mask"], $color, $target_dir, $color);
$completed++;
}
if (empty($parameters["icons"])) {
$task->set("mode", "copy_standard_css");
$task->status = t("Icons generated");
}
break;
case "copy_standard_css":
$task->status = t("Copying standard css");
while (!empty($parameters["standard_css"]) && microtime(true) - $start < 1.5) {
$css = array_shift($parameters["standard_css"]);
$target = "{$theme_path}css/" . basename($css);
if (!file_exists($target)) {
copy($css, $target);
if (empty($parameters["views"])){
$task->status = t("Views copied");
$task->set("mode", "copy_themeroller_images");
}
$completed++;
}
if (empty($parameters["standard_css"])){
$task->status = t("Standard css copied");
$task->set("mode", "copy_javascript");
}
break;
case "copy_javascript":
$task->status = t("Copying javascript");
while (!empty($parameters["js"]) && microtime(true) - $start < 1.5) {
$js = array_shift($parameters["js"]);
$target = "{$theme_path}js/" . str_replace(array("admin_", "site_"), "", basename($js));
if (!file_exists($target)) {
copy($js, $target);
break;
case "copy_themeroller_images":
$task->status = t("Copying themeroller images");
while (!empty($parameters["images"]) && microtime(true) - $start < 1.5) {
$image = array_shift($parameters["images"]);
$target = "{$theme_path}css/themeroller/images/" . basename($image);
if (!file_exists($target)) {
copy($image, $target);
$task->log(t("Copied themeroller image: %path", array("path" => basename($image))));
}
$completed++;
}
$completed++;
}
if (empty($parameters["js"])){
$task->status = t("Javascript copied");
$task->set("mode", "generate_screen_css");
if (empty($parameters["views"])){
$task->status = t("Themeroller images copied");
$task->set("mode", "copy_css");
}
break;
case "copy_css":
$task->status = t("Copying themeroller css");
$target = "{$theme_path}css/themeroller/ui.base.css";
copy($parameters["css_files"][0], $target);
$completed++;
$task->log(t("Copied themeroller css: themeroller/ui.base.css"));
$task->status = t("Themeroller css copied");
$task->set("mode", "generate_images");
break;
case "generate_images":
$task->status = t("Generating gallery images");
$target_dir = "{$theme_path}images/";
$colors = $task->get("colors");
$image_color = $parameters["colors"]["iconColorContent"];
while (!empty($parameters["masks"]) && microtime(true) - $start < 1.5) {
$mask = array_shift($parameters["masks"]);
$image_file = themeroller::generate_image($mask, $image_color, $target_dir);
$completed++;
$task->log(t("Generated image: %path", array("path" => $image_file)));
}
if (empty($parameters["masks"])) {
$task->set("mode", "generate_icons");
$task->status = t("Gallery images generated");
}
break;
case "generate_icons":
$task->status = t("Generating icons");
$target_dir = "{$theme_path}css/themeroller/images/";
while (!empty($parameters["icons"]) && microtime(true) - $start < 1.5) {
$color = array_shift($parameters["icons"]);
$icon_file = themeroller::generate_image($parameters["icon_mask"], $color, $target_dir, "_$color");
$completed++;
$task->log(t("Generated themeroller icon: %path", array("path" => $icon_file)));
}
if (empty($parameters["icons"])) {
$task->set("mode", "copy_standard_css");
$task->status = t("Icons generated");
}
break;
case "copy_standard_css":
$task->status = t("Copying standard css");
while (!empty($parameters["standard_css"]) && microtime(true) - $start < 1.5) {
$css = array_shift($parameters["standard_css"]);
$target = "{$theme_path}css/" . basename($css);
if (!file_exists($target)) {
copy($css, $target);
$task->log(t("Copied css file: %path", array("path" => basename($target))));
}
$completed++;
}
if (empty($parameters["standard_css"])){
$task->status = t("Standard css copied");
$task->set("mode", "copy_javascript");
}
break;
case "copy_javascript":
$task->status = t("Copying javascript");
while (!empty($parameters["js"]) && microtime(true) - $start < 1.5) {
$js = array_shift($parameters["js"]);
$target = "{$theme_path}js/" . str_replace(array("admin_", "site_"), "", basename($js));
if (!file_exists($target)) {
copy($js, $target);
$task->log(t("Copied js file: %path", array("path" => basename($target))));
}
$completed++;
}
if (empty($parameters["js"])){
$task->status = t("Javascript copied");
$task->set("mode", "generate_screen_css");
}
break;
case "generate_screen_css":
$file = "{$theme_path}/css/screen.css";
$v = new View(($is_admin ? "admin" : "site") . "_screen.css");
$v->display_name = $task->get("display_name");
foreach ($parameters["colors"] as $color => $value) {
$v->$color = $value;
}
ob_start();
print $v->render();
file_put_contents($file, ob_get_contents());
ob_end_clean();
$completed++;
$task->log(t("Generated screen css: %path", array("path" => $file)));
$task->status = t("Screen css generated");
$task->set("mode", "generate_thumbnail");
break;
case "generate_thumbnail":
themeroller::generate_thumbnail($parameters["thumbnail"],
$parameters["thumbnail_parts"],
"{$theme_path}thumbnail.png");
$task->status = t("Thumbnail generated");
$task->set("mode", "generate_theme_info");
$completed++;
$task->log(t("Generated theme thumbnail: %path", array("path" => "{$theme_path}thumbnail.png")));
break;
case "generate_theme_info":
$file = "{$theme_path}/theme.info";
$v = new View("theme.info");
$v->display_name = $task->get("display_name");
$v->description = $task->get("description");
$v->user_name = identity::active_user()->name;
$v->is_admin = $is_admin;
ob_start();
print $v->render();
file_put_contents($file, ob_get_contents());
ob_end_clean();
$completed++;
$task->log(t("Generated theme info: %path", array("path" => "{$theme_path}theme.info")));
$task->status = t("Theme info generated");
$task->set("mode", "done");
break;
case "done":
themeroller::recursive_directory_delete($task->get("path"));
$display_name = $task->get("display_name");
$task->done = true;
$task->state = "success";
$task->percent_complete = 100;
$completed = $task->get("total_activites");
Cache::instance()->delete("create_theme_cache:{$task->id}");
$message = t("Successfully generated: %name", array("name" => $display_name));
message::info($message);
$task->log($message);
$task->status = t("Theme '%name' generated", array("name" => $display_name));
}
break;
case "generate_screen_css":
$file = "{$theme_path}/css/screen.css";
$v = new View(($is_admin ? "admin" : "site") . "_screen.css");
$v->display_name = $task->get("display_name");
foreach ($parameters["colors"] as $color => $value) {
$v->$color = $value;
$task->set("completed", $completed);
if (!$task->done) {
Cache::instance()->set("create_theme_cache:{$task->id}", serialize($parameters));
$task->percent_complete = ($completed / $task->get("total_activites")) * 100;
}
ob_start();
print $v->render();
file_put_contents($file, ob_get_contents());
ob_end_clean();
$completed++;
$task->status = t("Screen css generated");
$task->set("mode", "generate_thumbnail");
break;
case "generate_thumbnail":
themeroller::generate_thumbnail($parameters["thumbnail"],
$parameters["thumbnail_parts"],
"{$theme_path}thumbnail.png");
$task->status = t("Thumbnail generated");
$task->set("mode", "generate_theme_info");
$completed++;
break;
case "generate_theme_info":
$file = "{$theme_path}/theme.info";
$v = new View("theme.info");
$v->display_name = $task->get("display_name");
$v->description = $task->get("description");
$v->user_name = identity::active_user()->name;
$v->is_admin = $is_admin;
ob_start();
print $v->render();
file_put_contents($file, ob_get_contents());
ob_end_clean();
$completed++;
$task->status = t("Theme info generated");
$task->set("mode", "done");
break;
case "done":
themeroller::recursive_directory_delete($task->get("path"));
$display_name = $task->get("display_name");
} catch (Exception $e) {
Kohana_Log::add("error",(string)$e);
$task->done = true;
$task->state = "success";
$task->percent_complete = 100;
$completed = $task->get("total_activites");
message::info(t("Successfully generated: %name", array("name" => $display_name)));
$task->state = "error";
$task->status = $e->getMessage();
$task->log((string)$e);
}
$task->set("completed", $completed);
$task->set("parameters", $parameters);
$task->percent_complete = ($completed / $task->get("total_activites")) * 100;
}
}

View File

@ -484,7 +484,7 @@ th {
}
.sf-sub-indicator {
background-image: url("themeroller/images/ui-icons_2e83ff_256x240.png");
background-image: url("themeroller/images/ui-icons_<?= $iconColorHighlight ?>_256x240.png");
height: 16px;
width: 16px;
}

View File

@ -526,11 +526,7 @@ td {
/* Superfish menu overrides ~~~~~~~~~~~~~~ */
.sf-menu a {
<<<<<<< HEAD
border-left:1px solid #<?= $borderColorContent ?>;
=======
border-left:1px solid #a6c9e2; /* borderColorContent */
>>>>>>> 64332d66885c485bee45bd5a8c3fcaee631119ca
}
.sf-menu li,
@ -552,7 +548,7 @@ td {
}
.sf-sub-indicator {
background-image: url("themeroller/images/ui-icons_2e83ff_256x240.png");
background-image: url("themeroller/images/ui-icons_<?= $iconColorHighlight ?>_256x240.png");
height: 16px;
width: 16px;
}