changes for FS#145
This commit is contained in:
parent
7f51b1035d
commit
8797b3820e
|
@ -1110,6 +1110,8 @@ function cpm_write_thumbnail($input, $target_filename, $do_rebuild = false) {
|
||||||
case CPM_SCALE_NONE:
|
case CPM_SCALE_NONE:
|
||||||
return null;
|
return null;
|
||||||
case CPM_SCALE_IMAGEMAGICK:
|
case CPM_SCALE_IMAGEMAGICK:
|
||||||
|
$original_size = getimagesize($input);
|
||||||
|
|
||||||
$unique_colors = exec("identify -format '%k' '${input}'");
|
$unique_colors = exec("identify -format '%k' '${input}'");
|
||||||
if (empty($unique_colors)) { $unique_colors = 256; }
|
if (empty($unique_colors)) { $unique_colors = 256; }
|
||||||
|
|
||||||
|
@ -1119,43 +1121,47 @@ function cpm_write_thumbnail($input, $target_filename, $do_rebuild = false) {
|
||||||
? $cpm_config->properties["${type}_comic_width"]
|
? $cpm_config->properties["${type}_comic_width"]
|
||||||
: $cpm_config->properties['archive_comic_width'];
|
: $cpm_config->properties['archive_comic_width'];
|
||||||
|
|
||||||
$command = array("convert",
|
if ($width_to_use < $original_size[0]) {
|
||||||
"\"${input}\"",
|
$command = array("convert",
|
||||||
"-filter Lanczos",
|
"\"${input}\"",
|
||||||
"-resize " . $width_to_use . "x");
|
"-filter Lanczos",
|
||||||
|
"-resize " . $width_to_use . "x");
|
||||||
|
|
||||||
$im_target = $target;
|
$im_target = $target;
|
||||||
|
|
||||||
switch(strtolower($target_format)) {
|
switch(strtolower($target_format)) {
|
||||||
case "jpg":
|
case "jpg":
|
||||||
case "jpeg":
|
case "jpeg":
|
||||||
$command[] = "-quality " . cpm_option("cpm-thumbnail-quality");
|
$command[] = "-quality " . cpm_option("cpm-thumbnail-quality");
|
||||||
break;
|
break;
|
||||||
case "gif":
|
case "gif":
|
||||||
$command[] = "-colors ${unique_colors}";
|
$command[] = "-colors ${unique_colors}";
|
||||||
break;
|
break;
|
||||||
case "png":
|
case "png":
|
||||||
if ($unique_colors <= 256) {
|
if ($unique_colors <= 256) {
|
||||||
$im_target = "png8:${im_target}";
|
$im_target = "png8:${im_target}";
|
||||||
$command[] = "-colors ${unique_colors}";
|
$command[] = "-colors ${unique_colors}";
|
||||||
}
|
}
|
||||||
$command[] = "-quality 100";
|
$command[] = "-quality 100";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
$command[] = "\"${im_target}\"";
|
$command[] = "\"${im_target}\"";
|
||||||
|
|
||||||
$convert_to_thumb = escapeshellcmd(implode(" ", $command));
|
$convert_to_thumb = escapeshellcmd(implode(" ", $command));
|
||||||
|
|
||||||
exec($convert_to_thumb);
|
exec($convert_to_thumb);
|
||||||
|
|
||||||
if (!file_exists($target)) {
|
if (!file_exists($target)) {
|
||||||
$ok = false;
|
$ok = false;
|
||||||
} else {
|
} else {
|
||||||
@chmod($target, CPM_FILE_UPLOAD_CHMOD);
|
@chmod($target, CPM_FILE_UPLOAD_CHMOD);
|
||||||
$files_created_in_operation[] = $target;
|
$files_created_in_operation[] = $target;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
copy($input, $target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($ok) ? $files_created_in_operation :false ;
|
return ($ok) ? $files_created_in_operation :false ;
|
||||||
|
@ -1197,85 +1203,89 @@ function cpm_write_thumbnail($input, $target_filename, $do_rebuild = false) {
|
||||||
? $cpm_config->properties["${type}_comic_width"]
|
? $cpm_config->properties["${type}_comic_width"]
|
||||||
: $cpm_config->properties['archive_comic_width'];
|
: $cpm_config->properties['archive_comic_width'];
|
||||||
|
|
||||||
$archive_comic_height = (int)(($width_to_use * $height) / $width);
|
if ($width_to_use < $width) {
|
||||||
|
$archive_comic_height = (int)(($width_to_use * $height) / $width);
|
||||||
|
|
||||||
$pathinfo = pathinfo($input);
|
$pathinfo = pathinfo($input);
|
||||||
|
|
||||||
$thumb_image = imagecreatetruecolor($width_to_use, $archive_comic_height);
|
$thumb_image = imagecreatetruecolor($width_to_use, $archive_comic_height);
|
||||||
imagealphablending($thumb_image, true);
|
imagealphablending($thumb_image, true);
|
||||||
switch(strtolower($pathinfo['extension'])) {
|
switch(strtolower($pathinfo['extension'])) {
|
||||||
case "jpg":
|
case "jpg":
|
||||||
case "jpeg":
|
case "jpeg":
|
||||||
$comic_image = imagecreatefromjpeg($input);
|
$comic_image = imagecreatefromjpeg($input);
|
||||||
break;
|
break;
|
||||||
case "gif":
|
case "gif":
|
||||||
$is_gif = true;
|
$is_gif = true;
|
||||||
|
|
||||||
$temp_comic_image = imagecreatefromgif($input);
|
$temp_comic_image = imagecreatefromgif($input);
|
||||||
|
|
||||||
list($width, $height) = getimagesize($input);
|
list($width, $height) = getimagesize($input);
|
||||||
$comic_image = imagecreatetruecolor($width, $height);
|
$comic_image = imagecreatetruecolor($width, $height);
|
||||||
|
|
||||||
imagecopy($comic_image, $temp_comic_image, 0, 0, 0, 0, $width, $height);
|
imagecopy($comic_image, $temp_comic_image, 0, 0, 0, 0, $width, $height);
|
||||||
imagedestroy($temp_comic_image);
|
imagedestroy($temp_comic_image);
|
||||||
break;
|
break;
|
||||||
case "png":
|
case "png":
|
||||||
$comic_image = imagecreatefrompng($input);
|
$comic_image = imagecreatefrompng($input);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
imagealphablending($comic_image, true);
|
imagealphablending($comic_image, true);
|
||||||
|
|
||||||
if ($is_palette = !imageistruecolor($comic_image)) {
|
if ($is_palette = !imageistruecolor($comic_image)) {
|
||||||
$number_of_colors = imagecolorstotal($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);
|
imagecopyresampled($thumb_image, $comic_image, 0, 0, 0, 0, $width_to_use, $archive_comic_height, $width, $height);
|
||||||
|
|
||||||
$ok = true;
|
$ok = true;
|
||||||
|
|
||||||
@touch($target);
|
@touch($target);
|
||||||
if (file_exists($target)) {
|
if (file_exists($target)) {
|
||||||
@unlink($target);
|
@unlink($target);
|
||||||
switch(strtolower($target_format)) {
|
switch(strtolower($target_format)) {
|
||||||
case "jpg":
|
case "jpg":
|
||||||
case "jpeg":
|
case "jpeg":
|
||||||
if (imagetypes() & IMG_JPG) {
|
if (imagetypes() & IMG_JPG) {
|
||||||
@imagejpeg($thumb_image, $target, cpm_option("cpm-thumbnail-quality"));
|
@imagejpeg($thumb_image, $target, cpm_option("cpm-thumbnail-quality"));
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "gif":
|
case "gif":
|
||||||
if (imagetypes() & IMG_GIF) {
|
if (imagetypes() & IMG_GIF) {
|
||||||
if (function_exists('imagecolormatch')) {
|
if (function_exists('imagecolormatch')) {
|
||||||
$temp_comic_image = imagecreate($width_to_use, $archive_comic_height);
|
$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);
|
imagecopymerge($temp_comic_image, $thumb_image, 0, 0, 0, 0, $width_to_use, $archive_comic_height, 100);
|
||||||
imagecolormatch($thumb_image, $temp_comic_image);
|
imagecolormatch($thumb_image, $temp_comic_image);
|
||||||
|
|
||||||
@imagegif($temp_comic_image, $target);
|
@imagegif($temp_comic_image, $target);
|
||||||
imagedestroy($temp_comic_image);
|
imagedestroy($temp_comic_image);
|
||||||
} else {
|
} else {
|
||||||
@imagegif($thumb_image, $target);
|
@imagegif($thumb_image, $target);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "png":
|
case "png":
|
||||||
if (imagetypes() & IMG_PNG) {
|
if (imagetypes() & IMG_PNG) {
|
||||||
if ($is_palette) {
|
if ($is_palette) {
|
||||||
imagetruecolortopalette($thumb_image, true, $number_of_colors);
|
imagetruecolortopalette($thumb_image, true, $number_of_colors);
|
||||||
}
|
}
|
||||||
@imagepng($thumb_image, $target, 9);
|
@imagepng($thumb_image, $target, 9);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
copy($input, $target);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists($target)) {
|
if (!file_exists($target)) {
|
||||||
|
|
|
@ -173,8 +173,11 @@ function cpm_build_comic_uri($filename, $base_dir = null) {
|
||||||
function cpm_breakdown_comic_filename($filename, $allow_override = false) {
|
function cpm_breakdown_comic_filename($filename, $allow_override = false) {
|
||||||
$pattern = CPM_DATE_FORMAT;
|
$pattern = CPM_DATE_FORMAT;
|
||||||
if ($allow_override !== false) {
|
if ($allow_override !== false) {
|
||||||
$pattern = $allow_override;
|
if (is_string($allow_override)) {
|
||||||
if (isset($_POST['upload-date-format']) && !empty($_POST['upload-date-format'])) { $pattern = $_POST['upload-date-format']; }
|
$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) {
|
foreach (array('[0-9]{4}', '[0-9]{2}') as $year_pattern) {
|
||||||
|
|
Loading…
Reference in New Issue