Example #1
0
 /**
  * @param string $name
  * @param array  $headers
  *
  * @return static
  */
 public static function create($name, array $headers = [])
 {
     $container = new self($name);
     $container->setHeaders($headers);
     // set visibility
     if (strstr($container->getMetadata()->get('Read'), '.r:*') !== false) {
         $container->setPublic();
     } else {
         $container->setPrivate();
     }
     // set object count
     if (null !== ($count = $container->headers->get('X-Container-Object-Count'))) {
         $container->setObjectCount($count);
     }
     // set bytes
     if (null !== ($bytes = $container->headers->get('X-Container-Bytes-Used'))) {
         $container->setBytesUsed($bytes);
     }
     return $container;
 }
Example #2
0
 /**
  * Useful method to calculate real crop measures. Used when you crop an image
  * which is smaller than the original one. In those cases you can call
  * calculateCropMeasures to retrieve the real $ox, $oy, $dx & $dy of the
  * image to be cropped.
  *
  * Note that you need to set the destiny image and pass the smaller (cropped)
  * image to this function.
  *
  * @param  string|Image $croppedFile The cropped image.
  * @param  mixed        $ox          Origin X.
  * @param  int          $oy          Origin Y.
  * @param  int          $dx          Destiny X.
  * @param  int          $dy          Destiny Y.
  * @return array
  */
 public function calculateCropMeasures($croppedFile, $ox, $oy = null, $dx = null, $dy = null)
 {
     list($ox, $oy, $dx, $dy) = Normalize::cropMeasures($ox, $oy, $dx, $dy);
     if (!$croppedFile instanceof self) {
         $croppedFile = new self($croppedFile);
     }
     $meta = $croppedFile->getMetadata();
     $rateWidth = $this->width / $meta['width'];
     $rateHeight = $this->height / $meta['height'];
     $ox = round($ox * $rateWidth);
     $oy = round($oy * $rateHeight);
     $dx = round($dx * $rateHeight);
     $dy = round($dy * $rateHeight);
     $width = $dx - $ox;
     $height = $dy - $oy;
     return [$ox, $oy, $dx, $dy, $width, $height];
 }
Example #3
0
 /**
  * Parse a info object from a string
  *
  * @param  string $stream
  * @return InfoObject
  */
 public static function parse($stream)
 {
     $info = new self();
     $info->setIndex(substr($stream, 0, strpos($stream, ' ')));
     $stream = str_replace($info->getIndex() . ' 0 obj', '[{info_index}] 0 obj', $stream);
     // Determine the Creator
     if (strpos($stream, '/Creator') !== false) {
         $creator = substr($stream, strpos($stream, '/Creator'));
         $creator = substr($creator, strpos($creator, '('));
         $creator = substr($creator, 0, strpos($creator, ')'));
         $creator = str_replace('(', '', $creator);
         $stream = str_replace('Creator(' . $creator . ')', 'Creator([{creator}])', $stream);
         $info->getMetadata()->setCreator($creator);
     } else {
         $stream = str_replace('>>', '/Creator([{creator}])>>', $stream);
     }
     // Determine the CreationDate
     if (strpos($stream, '/CreationDate') !== false) {
         $creationDate = substr($stream, strpos($stream, '/CreationDate'));
         $creationDate = substr($creationDate, strpos($creationDate, '('));
         $creationDate = substr($creationDate, 0, strpos($creationDate, ')'));
         $creationDate = str_replace('(', '', $creationDate);
         $stream = str_replace('CreationDate(' . $creationDate . ')', 'CreationDate([{creation_date}])', $stream);
         $info->getMetadata()->setCreationDate($creationDate);
     } else {
         $stream = str_replace('>>', '/CreationDate([{creation_date}])>>', $stream);
     }
     // Determine the ModDate
     if (strpos($stream, '/ModDate') !== false) {
         $modDate = substr($stream, strpos($stream, '/ModDate'));
         $modDate = substr($modDate, strpos($modDate, '('));
         $modDate = substr($modDate, 0, strpos($modDate, ')'));
         $modDate = str_replace('(', '', $modDate);
         $stream = str_replace('ModDate(' . $modDate . ')', 'ModDate([{mod_date}])', $stream);
         $info->getMetadata()->setModDate($modDate);
     } else {
         $stream = str_replace('>>', '/ModDate([{mod_date}])>>', $stream);
     }
     // Determine the Author
     if (strpos($stream, '/Author') !== false) {
         $author = substr($stream, strpos($stream, '/Author'));
         $author = substr($author, strpos($author, '('));
         $author = substr($author, 0, strpos($author, ')'));
         $author = str_replace('(', '', $author);
         $stream = str_replace('Author(' . $author . ')', 'Author([{author}])', $stream);
         $info->getMetadata()->setAuthor($author);
     } else {
         $stream = str_replace('>>', '/Author([{author}])>>', $stream);
     }
     // Determine the Title
     if (strpos($stream, '/Title') !== false) {
         $title = substr($stream, strpos($stream, '/Title'));
         $title = substr($title, strpos($title, '('));
         $title = substr($title, 0, strpos($title, ')'));
         $title = str_replace('(', '', $title);
         $stream = str_replace('Title(' . $title . ')', 'Title([{title}])', $stream);
         $info->getMetadata()->setTitle($title);
     } else {
         $stream = str_replace('>>', '/Title([{title}])>>', $stream);
     }
     // Determine the Subject
     if (strpos($stream, '/Subject') !== false) {
         $subject = substr($stream, strpos($stream, '/Subject'));
         $subject = substr($subject, strpos($subject, '('));
         $subject = substr($subject, 0, strpos($subject, ')'));
         $subject = str_replace('(', '', $subject);
         $stream = str_replace('Subject(' . $subject . ')', 'Subject([{subject}])', $stream);
         $info->getMetadata()->setSubject($subject);
     } else {
         $stream = str_replace('>>', '/Subject([{subject}])>>', $stream);
     }
     // Determine the Producer
     if (strpos($stream, '/Producer') !== false) {
         $producer = substr($stream, strpos($stream, '/Producer'));
         $producer = substr($producer, strpos($producer, '('));
         $producer = substr($producer, 0, strpos($producer, ')'));
         $producer = str_replace('(', '', $producer);
         $stream = str_replace('Producer(' . $producer . ')', 'Producer([{producer}])', $stream);
         $info->getMetadata()->setProducer($producer);
     } else {
         $stream = str_replace('>>', '/Producer([{producer}])>>', $stream);
     }
     $info->setData($stream);
     return $info;
 }