[fix] Aspect ratio conversions were wrong when printing.

This commit is contained in:
Solomon Peachy 2016-06-14 22:55:01 -04:00
parent 2497b4144b
commit b4acfca2ed
1 changed files with 39 additions and 11 deletions

View File

@ -67,10 +67,14 @@ function photo_print_single($database, $single) {
$retval = FALSE;
$output = "";
$printer = $single['printer'];
$version = $single['version'];
$title = $single['title'];
$rotate = FALSE;
$crop_factor_x = 0;
$crop_factor_y = 0;
$printer = $single['printer'];
$version = $single['version'];
$title = $single['title'];
if ($title == "")
$title = $strings['photo_no_title'] ." - $single[photo]";
@ -85,6 +89,11 @@ function photo_print_single($database, $single) {
$native_y = $photo_version_single['y_res'];
$original_name = $photo_version_single['original_image_name'];
if (($printer['target_x'] > $printer['target_y'] && $native_x < $native_y) ||
($printer['target_x'] < $printer['target_y'] && $native_x > $native_y)) {
$rotate = TRUE;
}
/* check for the source file's existence */
if (!is_file($file_name)) {
$output .= err_str($strings['errors_file_not_found'] ." : ". sprintf($strings['export_skipped'],emit_a(generate_link('photo', $single['photo']), $title)));
@ -93,8 +102,28 @@ function photo_print_single($database, $single) {
$output .= "<li>Printing $original_name - $single[photo]:$single[version]:$single[size]</li>\n";
# Size relations
$target_max = ($printer['target_x'] > $printer['target_y']) ? $printer['target_x'] : $printer['target_y'];
# Figure out scaling factor so we can crop sanely.
if ($rotate)
$in_ratio = $native_y / $native_x;
else
$in_ratio = $native_x / $native_y;
if ($in_ratio < 1) {
$target_min = $printer['target_x'];
$target_max = $printer['target_y'];
} else {
$in_ratio = 1 / $in_ratio;
$target_min = $printer['target_y'];
$target_max = $printer['target_x'];
}
# $output .= "<li>$native_x $native_y $target_min $target_max $in_ratio</li>";
if ($printer['target_x'] > $printer['target_y'])
$crop_factor_x = floor(($target_min / $in_ratio - $target_max) / 2);
else
$crop_factor_y = floor(($target_min / $in_ratio - $target_max) / 2);
$target_max = floor($target_min / $in_ratio);
# generate sane filename
$tmp_filename = tempnam($tmp_volume_path, "po.print.");
@ -114,13 +143,12 @@ function photo_print_single($database, $single) {
$cmdline .= " -resize ".$target_max."x".$target_max." ";
# rotate if needed
if (($printer['target_x'] > $printer['target_y'] && $native_x < $native_y) ||
($printer['target_x'] < $printer['target_y'] && $native_x > $native_y)) {
if ($rotate) {
$cmdline .= " -rotate 90 ";
}
# crop to final
$cmdline .= " -crop ".$printer['target_x']."x".$printer['target_y']."+0+0 +repage -gravity center ";
$cmdline .= " -crop ".$printer['target_x']."x".$printer['target_y']."+$crop_factor_x+$crop_factor_y "; // +repage -gravity center ";
# sharpen as needed
$cmdline .= " -unsharp ". escapeshellarg("0x". $printer['sharpen_sigma'] ."+". $printer['sharpen_amount'] ."+". $printer['sharpen_threshold']) . " ";
@ -129,7 +157,7 @@ function photo_print_single($database, $single) {
$cmdline .= " " . escapeshellarg($tmp_filename);
// $output .= "<pre>$cmdline</pre>\n";
# $output .= "<pre>$cmdline</pre>\n";
system($cmdline, $retval);
if ($retval) {
@ -147,7 +175,7 @@ function photo_print_single($database, $single) {
$cmdline .= " $tmp_filename ";
if (!$retval) {
// $output .= "<pre>$cmdline</pre>\n";
# $output .= "<pre>$cmdline</pre>\n";
system($cmdline, $retval);
if ($retval) {