Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from matslindh/6d9daf0747b07752b628061eba0ae1eb…
Browse files Browse the repository at this point in the history
…75d6206b

Add CMYK support for true black in EPS for print
  • Loading branch information
t0k4rt committed Dec 16, 2013
2 parents 8543524 + 6d9daf0 commit 650dc42
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
9 changes: 5 additions & 4 deletions qrencode.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $siz
}

//----------------------------------------------------------------------
public static function eps($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false, $back_color = 0xFFFFFF, $fore_color = 0x000000)
public static function eps($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false)
{
$enc = QRencode::factory($level, $size, $margin, $back_color, $fore_color);
$enc = QRencode::factory($level, $size, $margin, $back_color, $fore_color, $cmyk);
return $enc->encodeEPS($text, $outfile, $saveandprint=false);
}

Expand Down Expand Up @@ -424,13 +424,14 @@ class QRencode {
public $hint = QR_MODE_8;

//----------------------------------------------------------------------
public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000)
public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false)
{
$enc = new QRencode();
$enc->size = $size;
$enc->margin = $margin;
$enc->fore_color = $fore_color;
$enc->back_color = $back_color;
$enc->cmyk = $cmyk;

switch ($level.'') {
case '0':
Expand Down Expand Up @@ -533,7 +534,7 @@ public function encodeEPS($intext, $outfile = false,$saveandprint=false)

$maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));

return QRvect::eps($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint, $this->back_color, $this->fore_color);
return QRvect::eps($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint, $this->back_color, $this->fore_color, $this->cmyk);

} catch (Exception $e) {

Expand Down
58 changes: 37 additions & 21 deletions qrvect.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@
class QRvect {

//----------------------------------------------------------------------
public static function eps($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color = 0xFFFFFF, $fore_color = 0x000000)
public static function eps($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false)
{
$vect = self::vectEPS($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color);
$vect = self::vectEPS($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color, $cmyk);

if ($filename === false) {
header("Content-Type: application/postscript");
header('Content-Disposition: filename="qrcode.eps"');
return $vect;
echo $vect;
} else {
if($saveandprint===TRUE){
QRtools::save($vect, $filename);
header("Content-Type: application/postscript");
header('Content-Disposition: filename="'.$filename.'"');
return $vect;
echo $vect;
}else{
QRtools::save($vect, $filename);
}
Expand All @@ -49,28 +49,44 @@ public static function eps($frame, $filename = false, $pixelPerPoint = 4, $outer


//----------------------------------------------------------------------
private static function vectEPS($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000)
private static function vectEPS($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false)
{
$h = count($frame);
$w = strlen($frame[0]);

$imgW = $w + 2*$outerFrame;
$imgH = $h + 2*$outerFrame;




// convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
$r = round((($fore_color & 0xFF0000) >> 16) / 255, 5);
$b = round((($fore_color & 0x00FF00) >> 8) / 255, 5);
$g = round(($fore_color & 0x0000FF) / 255, 5);
$fore_color = $r.' '.$b.' '.$g;

// convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
$r = round((($back_color & 0xFF0000) >> 16) / 255, 5);
$b = round((($back_color & 0x00FF00) >> 8) / 255, 5);
$g = round(($back_color & 0x0000FF) / 255, 5);
$back_color = $r.' '.$b.' '.$g;
if ($cmyk)
{
// convert color value into decimal eps format
$c = round((($fore_color & 0xFF000000) >> 16) / 255, 5);
$m = round((($fore_color & 0x00FF0000) >> 16) / 255, 5);
$y = round((($fore_color & 0x0000FF00) >> 8) / 255, 5);
$k = round(($fore_color & 0x000000FF) / 255, 5);
$fore_color_string = $c.' '.$m.' '.$y.' '.$k.' setcmykcolor'."\n";

// convert color value into decimal eps format
$c = round((($back_color & 0xFF000000) >> 16) / 255, 5);
$m = round((($back_color & 0x00FF0000) >> 16) / 255, 5);
$y = round((($back_color & 0x0000FF00) >> 8) / 255, 5);
$k = round(($back_color & 0x000000FF) / 255, 5);
$back_color_string = $c.' '.$m.' '.$y.' '.$k.' setcmykcolor'."\n";
}
else
{
// convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
$r = round((($fore_color & 0xFF0000) >> 16) / 255, 5);
$b = round((($fore_color & 0x00FF00) >> 8) / 255, 5);
$g = round(($fore_color & 0x0000FF) / 255, 5);
$fore_color_string = $r.' '.$b.' '.$g.' setrgbcolor'."\n";

// convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
$r = round((($back_color & 0xFF0000) >> 16) / 255, 5);
$b = round((($back_color & 0x00FF00) >> 8) / 255, 5);
$g = round(($back_color & 0x0000FF) / 255, 5);
$back_color_string = $r.' '.$b.' '.$g.' setrgbcolor'."\n";
}

$output =
'%!PS-Adobe EPSF-3.0'."\n".
Expand All @@ -95,12 +111,12 @@ private static function vectEPS($frame, $pixelPerPoint = 4, $outerFrame = 4, $ba
$output .= '/F { rectfill } def'."\n";

// set the symbol color
$output .= $back_color.' setrgbcolor'."\n";
$output .= $back_color_string;
$output .= '-'.$outerFrame.' -'.$outerFrame.' '.($w + 2*$outerFrame).' '.($h + 2*$outerFrame).' F'."\n";


// set the symbol color
$output .= $fore_color.' setrgbcolor'."\n";
$output .= $fore_color_string;

// Convert the matrix into pixels

Expand Down

0 comments on commit 650dc42

Please sign in to comment.