예제 #1
0
 public function testBitmap()
 {
     $bitmap = new Bitmap();
     $bitmap->setBit(0);
     $bitmap->setBit(2);
     $this->assertEquals('101', $bitmap->getBinary());
 }
예제 #2
0
 public function update()
 {
     if ($this->getId() > 0) {
         // we already have an id ...
     } else {
         // check if we have a record with this path
         $searchParams = array('relativePath' => $this->getRelativePath());
         // multiple usage of same image files are possible...
         if ($this->getAlbumId() > 0) {
             $searchParams['albumId'] = $this->getAlbumId();
         }
         $b2 = Bitmap::getInstanceByAttributes($searchParams);
         if ($b2 !== NULL) {
             $this->setId($b2->getId());
         } else {
             return $this->insert();
         }
     }
     $app = \Slim\Slim::getInstance();
     $query = 'UPDATE ' . self::$tableName . ' SET ';
     foreach ($this->mapInstancePropertiesToDatabaseKeys() as $dbfield => $value) {
         $query .= $dbfield . '="' . $app->db->real_escape_string($value) . '",';
     }
     $query = substr($query, 0, -1) . ' WHERE id=' . (int) $this->getId() . ";";
     $app->db->query($query);
 }
예제 #3
0
 function scaleProportional($width, $height = null, $direction = "center")
 {
     if ($height == null) {
         $height = $width / $this->ratio;
     }
     $newRatio = $width / $height;
     Logger::log("BMP", "ratios = {$this->ratio} = {$newRatio}");
     Logger::log("BMP", "dimensions = {$width} x {$height}");
     Logger::log("BMP", "og. dimensions = {$width} x {$height}");
     $x = 0;
     $y = 0;
     if ($newRatio == $this->ratio) {
         $resultWidth = $this->width;
         $resultHeight = $this->height;
     } else {
         if ($this->ratio > $newRatio) {
             Logger::log("BMP", "entra aqui >>> ");
             $resultHeight = $this->height;
             $resultWidth = $this->height * $newRatio;
             switch (strtolower($direction)) {
                 case "center":
                     $x = round(($this->width - $resultWidth) / 2);
                     break;
                 case "left":
                     $x = 0;
                     break;
                 case "right":
                     $x = $this->width - $resultWidth;
                     break;
             }
         } else {
             $resultWidth = $this->width;
             $resultHeight = $this->width / $newRatio;
             switch (strtolower($direction)) {
                 case "center":
                     $y = round(($this->height - $resultHeight) / 2);
                     break;
                 case "top":
                     $y = 0;
                     break;
                 case "bottom":
                     $y = $this->height - $resultHeight;
                     break;
             }
         }
     }
     Logger::log("BMP", "result dimensions = {$resultWidth} x {$resultHeight}");
     $newImage = imagecreatetruecolor($width, $height);
     /*switch ($this->extension){
     		    case "jpeg":
     		    case "jpg":
     		      $newImage = imagecreatetruecolor($width,$height);
     		      break;
     		    case "gif":
     		      $newImage = imagecreate($width,$height);
     		      break;
     		}*/
     //$newImage = $newMethodName($width,$height);
     imagecopyresampled($newImage, $this->imageHandler, 0, 0, $x, $y, $width, $height, $resultWidth, $resultHeight);
     //,$this->width,$this->height);
     $resultImage = new Bitmap();
     $resultImage->setImage($newImage);
     $resultImage->setExtension($this->extension);
     return $resultImage;
     /*
     @mkdir($this->fileName."_chache",0777,true);
     imagejpeg($newImage,$this->fileName."_chache/".$width."x".$height.".jpg",90);
     */
     //imagejpeg($thumbImage,$CACHE_BASE."{$thumbWidth}x{$thumbHeight}/".md5($srcImageURI),90);
 }
예제 #4
0
 /**
   Turn bitmap into receipt string
   @param $arg string filename OR Bitmap obj
   @return receipt-formatted string
 */
 function RenderBitmap($arg, $align = 'C')
 {
     $slip = "";
     if (!class_exists('Bitmap')) {
         return "";
     }
     $bmp = null;
     if (is_object($arg) && is_a($arg, 'Bitmap')) {
         $bmp = $arg;
     } else {
         if (file_exists($arg)) {
             $bmp = new Bitmap();
             $bmp->load($arg);
         }
     }
     // argument was invalid
     if ($bmp === null) {
         return "";
     }
     $bmpData = $bmp->getRawData();
     $bmpWidth = $bmp->getWidth();
     $bmpHeight = $bmp->getHeight();
     $bmpRawBytes = (int) (($bmpWidth + 7) / 8);
     $stripes = $this->TransposeBitmapData($bmpData, $bmpWidth);
     for ($i = 0; $i < count($stripes); $i++) {
         $stripes[$i] = $this->InlineBitmap($stripes[$i], $bmpWidth);
     }
     if ($align == 'C') {
         $slip .= $this->AlignCenter();
     }
     if (count($stripes) > 1) {
         $slip .= $this->LineSpacing(0);
     }
     $slip .= implode("\n", $stripes);
     if (count($stripes) > 1) {
         $slip .= $this->ResetLineSpacing();
     }
     if ($align == 'C') {
         $slip .= "\n";
     }
     $slip .= $this->AlignLeft();
     return $slip;
 }
예제 #5
0
 /**
  * Insert a 24bit bitmap image in a worksheet.
  *
  * @param integer $row     The row we are going to insert the bitmap into
  * @param integer $col     The column we are going to insert the bitmap into
  * @param string $path  The bitmap filename
  * @param integer $x       The horizontal position (offset) of the image inside the cell.
  * @param integer $y       The vertical position (offset) of the image inside the cell.
  * @param integer $scaleX The horizontal scale
  * @param integer $scaleY The vertical scale
  */
 public function insertBitmap($row, $col, $path, $x = 0, $y = 0, $scaleX = 1, $scaleY = 1)
 {
     $bmp = new Bitmap($path);
     $width = $bmp->getWidth();
     $height = $bmp->getHeight();
     // BITMAPCOREINFO
     $data = $this->getRecord('BitmapCoreHeader', array($width, $height));
     $data .= $bmp->getDataWithoutHeader();
     // Scale the frame of the image.
     $width *= $scaleX;
     $height *= $scaleY;
     $this->positionImage($col, $row, $x, $y, $width, $height);
     $this->appendRecord('Imdata', array($data));
 }
예제 #6
0
 public static function graphedLocalTTL()
 {
     $db = Database::tDataConnect();
     $lookup = "SELECT \n        SUM(CASE WHEN p.local=1 THEN l.total ELSE 0 END) as localTTL,\n        SUM(CASE WHEN l.trans_type IN ('I','D') then l.total ELSE 0 END) as itemTTL\n        FROM localtemptrans AS l LEFT JOIN " . CoreLocal::get('pDatabase') . $db->sep() . "products AS p\n        ON l.upc=p.upc\n        WHERE l.trans_type IN ('I','D')";
     $lookup = $db->query($lookup);
     if ($db->num_rows($lookup) == 0) {
         return '';
     }
     $row = $db->fetch_row($lookup);
     if ($row['localTTL'] == 0) {
         return '';
     }
     $percent = (double) $row['localTTL'] / (double) $row['itemTTL'];
     $str = sprintf('LOCAL PURCHASES = $%.2f (%.2f%%)', $row['localTTL'], 100 * $percent);
     $str .= "\n";
     $str .= self::$PRINT_OBJ->RenderBitmap(Bitmap::barGraph($percent), 'L');
     return $str . "\n";
 }