Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Commit

Permalink
changes for FS#145
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbintz committed Mar 19, 2010
1 parent 7f51b10 commit 8797b38
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 118 deletions.
242 changes: 126 additions & 116 deletions comicpress_manager_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,8 @@ function cpm_write_thumbnail($input, $target_filename, $do_rebuild = false) {
case CPM_SCALE_NONE:
return null;
case CPM_SCALE_IMAGEMAGICK:
$original_size = getimagesize($input);

$unique_colors = exec("identify -format '%k' '${input}'");
if (empty($unique_colors)) { $unique_colors = 256; }

Expand All @@ -1119,43 +1121,47 @@ function cpm_write_thumbnail($input, $target_filename, $do_rebuild = false) {
? $cpm_config->properties["${type}_comic_width"]
: $cpm_config->properties['archive_comic_width'];

$command = array("convert",
"\"${input}\"",
"-filter Lanczos",
"-resize " . $width_to_use . "x");

$im_target = $target;

switch(strtolower($target_format)) {
case "jpg":
case "jpeg":
$command[] = "-quality " . cpm_option("cpm-thumbnail-quality");
break;
case "gif":
$command[] = "-colors ${unique_colors}";
break;
case "png":
if ($unique_colors <= 256) {
$im_target = "png8:${im_target}";
$command[] = "-colors ${unique_colors}";
}
$command[] = "-quality 100";
break;
default:
}

$command[] = "\"${im_target}\"";

$convert_to_thumb = escapeshellcmd(implode(" ", $command));

exec($convert_to_thumb);

if (!file_exists($target)) {
$ok = false;
} else {
@chmod($target, CPM_FILE_UPLOAD_CHMOD);
$files_created_in_operation[] = $target;
}
if ($width_to_use < $original_size[0]) {
$command = array("convert",
"\"${input}\"",
"-filter Lanczos",
"-resize " . $width_to_use . "x");

$im_target = $target;

switch(strtolower($target_format)) {
case "jpg":
case "jpeg":
$command[] = "-quality " . cpm_option("cpm-thumbnail-quality");
break;
case "gif":
$command[] = "-colors ${unique_colors}";
break;
case "png":
if ($unique_colors <= 256) {
$im_target = "png8:${im_target}";
$command[] = "-colors ${unique_colors}";
}
$command[] = "-quality 100";
break;
default:
}

$command[] = "\"${im_target}\"";

$convert_to_thumb = escapeshellcmd(implode(" ", $command));

exec($convert_to_thumb);

if (!file_exists($target)) {
$ok = false;
} else {
@chmod($target, CPM_FILE_UPLOAD_CHMOD);
$files_created_in_operation[] = $target;
}
} else {
copy($input, $target);
}
}

return ($ok) ? $files_created_in_operation :false ;
Expand Down Expand Up @@ -1197,85 +1203,89 @@ function cpm_write_thumbnail($input, $target_filename, $do_rebuild = false) {
? $cpm_config->properties["${type}_comic_width"]
: $cpm_config->properties['archive_comic_width'];

$archive_comic_height = (int)(($width_to_use * $height) / $width);

$pathinfo = pathinfo($input);

$thumb_image = imagecreatetruecolor($width_to_use, $archive_comic_height);
imagealphablending($thumb_image, true);
switch(strtolower($pathinfo['extension'])) {
case "jpg":
case "jpeg":
$comic_image = imagecreatefromjpeg($input);
break;
case "gif":
$is_gif = true;

$temp_comic_image = imagecreatefromgif($input);

list($width, $height) = getimagesize($input);
$comic_image = imagecreatetruecolor($width, $height);

imagecopy($comic_image, $temp_comic_image, 0, 0, 0, 0, $width, $height);
imagedestroy($temp_comic_image);
break;
case "png":
$comic_image = imagecreatefrompng($input);
break;
default:
return false;
}
imagealphablending($comic_image, true);

if ($is_palette = !imageistruecolor($comic_image)) {
$number_of_colors = imagecolorstotal($comic_image);
}

imagecopyresampled($thumb_image, $comic_image, 0, 0, 0, 0, $width_to_use, $archive_comic_height, $width, $height);

$ok = true;

@touch($target);
if (file_exists($target)) {
@unlink($target);
switch(strtolower($target_format)) {
case "jpg":
case "jpeg":
if (imagetypes() & IMG_JPG) {
@imagejpeg($thumb_image, $target, cpm_option("cpm-thumbnail-quality"));
} else {
return false;
}
break;
case "gif":
if (imagetypes() & IMG_GIF) {
if (function_exists('imagecolormatch')) {
$temp_comic_image = imagecreate($width_to_use, $archive_comic_height);
imagecopymerge($temp_comic_image, $thumb_image, 0, 0, 0, 0, $width_to_use, $archive_comic_height, 100);
imagecolormatch($thumb_image, $temp_comic_image);

@imagegif($temp_comic_image, $target);
imagedestroy($temp_comic_image);
} else {
@imagegif($thumb_image, $target);
}
} else {
return false;
}
break;
case "png":
if (imagetypes() & IMG_PNG) {
if ($is_palette) {
imagetruecolortopalette($thumb_image, true, $number_of_colors);
}
@imagepng($thumb_image, $target, 9);
} else {
return false;
}
break;
default:
return false;
}
if ($width_to_use < $width) {
$archive_comic_height = (int)(($width_to_use * $height) / $width);

$pathinfo = pathinfo($input);

$thumb_image = imagecreatetruecolor($width_to_use, $archive_comic_height);
imagealphablending($thumb_image, true);
switch(strtolower($pathinfo['extension'])) {
case "jpg":
case "jpeg":
$comic_image = imagecreatefromjpeg($input);
break;
case "gif":
$is_gif = true;

$temp_comic_image = imagecreatefromgif($input);

list($width, $height) = getimagesize($input);
$comic_image = imagecreatetruecolor($width, $height);

imagecopy($comic_image, $temp_comic_image, 0, 0, 0, 0, $width, $height);
imagedestroy($temp_comic_image);
break;
case "png":
$comic_image = imagecreatefrompng($input);
break;
default:
return false;
}
imagealphablending($comic_image, true);

if ($is_palette = !imageistruecolor($comic_image)) {
$number_of_colors = imagecolorstotal($comic_image);
}

imagecopyresampled($thumb_image, $comic_image, 0, 0, 0, 0, $width_to_use, $archive_comic_height, $width, $height);

$ok = true;

@touch($target);
if (file_exists($target)) {
@unlink($target);
switch(strtolower($target_format)) {
case "jpg":
case "jpeg":
if (imagetypes() & IMG_JPG) {
@imagejpeg($thumb_image, $target, cpm_option("cpm-thumbnail-quality"));
} else {
return false;
}
break;
case "gif":
if (imagetypes() & IMG_GIF) {
if (function_exists('imagecolormatch')) {
$temp_comic_image = imagecreate($width_to_use, $archive_comic_height);
imagecopymerge($temp_comic_image, $thumb_image, 0, 0, 0, 0, $width_to_use, $archive_comic_height, 100);
imagecolormatch($thumb_image, $temp_comic_image);

@imagegif($temp_comic_image, $target);
imagedestroy($temp_comic_image);
} else {
@imagegif($thumb_image, $target);
}
} else {
return false;
}
break;
case "png":
if (imagetypes() & IMG_PNG) {
if ($is_palette) {
imagetruecolortopalette($thumb_image, true, $number_of_colors);
}
@imagepng($thumb_image, $target, 9);
} else {
return false;
}
break;
default:
return false;
}
}
} else {
copy($input, $target);
}

if (!file_exists($target)) {
Expand Down
7 changes: 5 additions & 2 deletions comicpress_manager_library.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ function cpm_build_comic_uri($filename, $base_dir = null) {
function cpm_breakdown_comic_filename($filename, $allow_override = false) {
$pattern = CPM_DATE_FORMAT;
if ($allow_override !== false) {
$pattern = $allow_override;
if (isset($_POST['upload-date-format']) && !empty($_POST['upload-date-format'])) { $pattern = $_POST['upload-date-format']; }
if (is_string($allow_override)) {
$pattern = $allow_override;
} else {
if (isset($_POST['upload-date-format']) && !empty($_POST['upload-date-format'])) { $pattern = $_POST['upload-date-format']; }
}
}

foreach (array('[0-9]{4}', '[0-9]{2}') as $year_pattern) {
Expand Down

0 comments on commit 8797b38

Please sign in to comment.