summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2016-06-14 22:55:01 -0400
committerSolomon Peachy <pizza@shaftnet.org>2016-06-14 22:55:01 -0400
commitb4acfca2ed8102809fcfafd66306ddda48f09668 (patch)
tree6177da547d6591260eb2bb55f8e272ef2a03409f
parent2497b4144bfb1586bfba59d2575d57db7ec5bbaa (diff)
downloadpo-b4acfca2ed8102809fcfafd66306ddda48f09668.tar.gz
po-b4acfca2ed8102809fcfafd66306ddda48f09668.tar.bz2
po-b4acfca2ed8102809fcfafd66306ddda48f09668.zip
[fix] Aspect ratio conversions were wrong when printing.
-rw-r--r--src/include/print.printer.php50
1 files changed, 39 insertions, 11 deletions
diff --git a/src/include/print.printer.php b/src/include/print.printer.php
index 2bd61c5..6f54333 100644
--- a/src/include/print.printer.php
+++ b/src/include/print.printer.php
@@ -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) {