Printing Accurately Scaled Images From A Browser
5 posts by 3 authors in: Forums > CMS Builder
Last Post: September 9, 2015 (RSS)
By gkornbluth - September 5, 2015 - edited: September 5, 2015
Hi All,
I’m trying to accomplish what should be a relatively straight forward thing to do.
I want to print a series of artwork images pulled from an upload field directly from a browser, and need the prints to be scaled at 1 inch to the foot.
I’ve entered the artwork width (in inches) into the image’s info1 field and the height (in inches) into the image’s info2 field
The math works to change the pixel size of the image, and if downloaded all resulting image, it will print correctly from within any image editing program.
But, when I try to print the images directly from any browser, it prints smaller, and there doesn’t seem to be a simple correlation between ppi and print size when print a number of images with different pixel dimensions.
I’ve tried everything I can think of, including trying to use the new image-resolution CSS tag, only to find that it’s not yet supported in any browser.
I’m lost... and hope that someone has dealt with this before, or has an idea how to solve the mystery.
Below is the code that I’ve put together so far.
Thanks,
Jerry Kornbluth
<?php $ppi = 96 // possible browser print resolution ?>
<>php $scale = 12 // scale inches per foot ?>
<?php foreach ($image_uploadsRecords as $record): ?>
<?php foreach ($record['uploads'] as $index => $upload): ?>
<?php $ratio1 = $upload['width']/$upload['info1'] // image pixel width / actual inches ?>
<?php $ratio2 = $upload['height']/$upload['info2'] // image pixel height / actual inches ?>
<?php $ratio3 = $ppi/$ratio1?>
<?php $ratio4 = $ppi/$ratio2?>
<?php $width = (($upload['width']*$ratio3))/$scale ?>
<?php $width = number_format($width, 0) ?>
<?php $height = (($upload['height']*$ratio4))/$scale ?>
<?php $height = number_format($height, 0) ?>
<div align="center"><br /><img src="<?php echo htmlencode($upload['urlPath']) ?>" width="<?php echo $width ?>" height="<?php echo $height ?>" alt="" /><br /><div align="center">
<br /><?php echo $upload['info1'] ?>''W (<?php echo $width ?>px) <?php echo $upload['info2'] ?>''H (<?php echo $height ?>px) at <?php echo $ppi ?>PPI<br />
<?php endforeach ?>
<?php endforeach ?>
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By Toledoh - September 6, 2015
Hey Jerry. Could you use the PDF generation plugin?
Tim (toledoh.com.au)
Hi Tim,
Thanks for responding.
I tried that but got the same results.
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Hey Jerry,
Tim's suggestion of using create PDF seems like the best solution to me, that way you can ensure the output is always a standard resolution and DPI no matter what browser is used to print the image.
You can set custom flags for the plugin to ensure it always exports using the same resolution and DPI. I set custom flags so that my output would always be 300 DPI and have a resolution of 1024 X 640. You can set these flags on line 16 of the createPDF plugin:
$GLOBALS['CREATEPDF_CUSTOM_SWITCHES'] = ' --page-width 1024px --page-height 640px --dpi 300'; // Set this in your script before called createPDF* functions to pass custom command line switches
Cheers,
Greg
PHP Programmer - interactivetools.com
Thanks Greg,
I'll give it a try and post my results.
Didn't know about the custom flags.
Jerry Kornbluth.
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php