コード例 #1
0
ファイル: image.php プロジェクト: pmvc-plugin/image
 public function getCenter(ImageSize $size, ImageSize $cut = null)
 {
     $aSize = $size->toArray();
     if (is_null($cut)) {
         $cut = new ImageSize();
     }
     $aCut = $cut->toArray();
     $x = round($aSize['w'] / 2);
     $y = round($aSize['h'] / 2);
     $x -= round($aCut['w'] / 2);
     $y -= round($aCut['h'] / 2);
     return new Coord2D($x, $y);
 }
コード例 #2
0
 /**
  * Apaga
  */
 public function deleteAction()
 {
     $status = false;
     if (isset($_POST)) {
         if (isset($_REQUEST['id'])) {
             $id = (int) $_REQUEST['id'];
             $image = Image::find($id);
             if ($image) {
                 $status = Image::delete($image->getId());
                 // Se a imagem foi apagada com sucesso realiza as demais ações
                 if ($status) {
                     // Apaga os tamanhos de imagem
                     $condition = sprintf("image_id = %s", $image->getId());
                     ImageSize::deleteAll($condition);
                     // Gerenciador de imagens
                     $imageManager = new ImageManager($image);
                     // Apaga o diretório das imagens
                     $imageManager->removeDir();
                 }
             }
         }
     }
     // Cria a variável flash
     if ($status) {
         $this->setFlash('notice_success', 'Image deleted successfully.');
     } else {
         $this->setFlash('notice_error', 'Delete image failed.');
     }
     // Redireciona para a listagem
     $this->redirectTo('image', 'list');
 }
コード例 #3
0
 /**
  * Apaga um tipo de imagem 
  */
 public function deleteAction()
 {
     $status = false;
     if (isset($_POST)) {
         if (isset($_REQUEST['id'])) {
             $id = (int) $_REQUEST['id'];
             // Apaga as imagens do disco
             $condition = sprintf("image_type_id = %s", $id);
             ImageSize::deleteAll($condition);
             $status = ImageType::delete($id);
         }
     }
     // Cria a variável flash
     if ($status) {
         $this->setFlash('notice_success', 'Image type deleted successfully.');
     } else {
         $this->setFlash('notice_error', 'Delete image type failed.');
     }
     // Redireciona para a listagem
     $this->redirectTo('imageType', 'list');
 }
コード例 #4
0
 /**
  * @param ImageSize $originalSize
  * @param ImageSize $newSize
  * @return ImageSize
  */
 private function getOptimalCrop(ImageSize $newSize)
 {
     $widthRatio = $this->getWidth() / $newSize->getWidth();
     $heightRatio = $this->getHeight() / $newSize->getHeight();
     if ($heightRatio < $widthRatio) {
         return new ImageSize($this->getWidth() / $heightRatio, $this->getHeight() / $heightRatio);
     } else {
         return new ImageSize($this->getWidth() / $widthRatio, $this->getHeight() / $widthRatio);
     }
 }
コード例 #5
0
ファイル: Image.php プロジェクト: patrickespake/go2images
 /**
  * Obtém todos os tamanhos de imagens disponíveis
  * @return array/object Informações dos tamanhos de imagens
  */
 public function getSizes()
 {
     $condition = sprintf("image_id = %s ORDER BY image_type_id ASC", $this->getId());
     return ImageSize::findAll($condition);
 }
コード例 #6
0
ファイル: imageinterface.php プロジェクト: netixx/frankiz
 protected static function loadConf()
 {
     global $globals;
     if (self::$sizes == null) {
         self::$sizes = array();
         self::$order = json_decode($globals->sizes->order);
         foreach (self::$order as $size) {
             self::$sizes[$size] = ImageSize::fromExport(json_decode($globals->sizes->{$size}));
         }
     }
 }
コード例 #7
0
ファイル: frankizimage.php プロジェクト: netixx/frankiz
 /**
  * Build the image from a FrankizUpload instance, stores it into the DB
  *
  * @param $fu      Instance of FrankizUpload
  * @param $rm      Should the temporary file be removed after ? (Default: yes)
  */
 public function image(FrankizUpload $fu, $rm = true)
 {
     $infos = getimagesize($fu->path());
     $this->mime = $infos['mime'];
     $types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG);
     if (!in_array($infos[2], $types)) {
         throw new ImageFormatException();
     }
     $this->x = $infos[0];
     $this->y = $infos[1];
     if ($this->x > ImageSize::MAX_WIDTH() || $this->y > ImageSize::MAX_HEIGHT()) {
         $e = new ImageSizeException('The picture is to big: (' . $this->x . 'x' . $this->y . ') > (' . ImageSize::MAX_WIDTH() . 'x' . ImageSize::MAX_HEIGHT() . ')');
         $e->size(new ImageSize($this->x, $this->y));
         $e->allowed(ImageSize::MAX());
         throw $e;
     }
     $this->images = ImageSizesSet::resize(file_get_contents($fu->path()));
     if ($rm) {
         $fu->rm();
     }
     foreach ($this->images as $size => $image) {
         $size_order = ImageSizesSet::sizeToOrder($size);
         XDB::execute('INSERT INTO  images_sizes
                               SET  iid = {?}, size = {?}, mime = {?}, x = {?}, y = {?}, data = {?}
           ON DUPLICATE KEY UPDATE  mime = {?}, x = {?}, y = {?}, data = {?}', $this->id(), $size_order, $image->mime, $image->x, $image->y, $image->data, $image->mime, $image->x, $image->y, $image->data);
     }
 }
コード例 #8
0
 /**
  * Realiza o crop da imagem para determinadas medidas
  * @param ImageType $imageType Informações do tipo de imagem
  */
 private function crop($imageType)
 {
     // Caminho da imagem a ser realizado crop
     $croppedImagePath = sprintf("%s/%s_%s", $this->getDirImagePath(), $imageType->getName(), $this->getName());
     // Dimensões da imagem que foi realizada resize
     $resizedImageSizes = $this->getResizedImageSizes();
     // Pontos x e y para crop
     $startHeight = ($resizedImageSizes['height'] - $imageType->getHeight()) / 2;
     $startWidth = ($resizedImageSizes['width'] - $imageType->getWidth()) / 2;
     // Cria a nova imagem
     $newImage = imagecreatetruecolor($imageType->getWidth(), $imageType->getHeight());
     $source = $this->getSource($this->getResizedImagePath());
     imagecopy($newImage, $source, 0, 0, $startWidth, $startHeight, $resizedImageSizes['width'], $resizedImageSizes['height']);
     $this->createImage($newImage, $croppedImagePath, $this->getResizedImagePath());
     chmod($croppedImagePath, 0777);
     // Apaga a imagem de resize
     unlink($this->getResizedImagePath());
     // Grava no banco de dados as informações do novo tamanho de imagem
     $imageSize = new ImageSize();
     $imageSize->setImage($this->getImage());
     $imageSize->setImageType($imageType);
     $imageSize->setFileName($croppedImagePath);
     $imageSize->setFileContentType($this->getMimeType($croppedImagePath));
     $imageSize->setFileSize(filesize($croppedImagePath));
     $imageSize->save();
 }
コード例 #9
0
ファイル: ImageResizer.php プロジェクト: crd2i/image-bundle
 /**
  * @param $img
  * @param $type
  * @param ImageSize $newSize
  * @param ImageSize $expectedSize
  * @return resource
  */
 private function crop($img, $type, ImageSize $newSize, ImageSize $expectedSize)
 {
     // Find center - this will be used for the crop
     $cropStartX = $newSize->getWidth() / 2 - $expectedSize->getWidth() / 2;
     $cropStartY = $newSize->getHeight() / 2 - $expectedSize->getHeight() / 2;
     // Now crop from center to exact requested size
     $imageCropped = imagecreatetruecolor($expectedSize->getWidth(), $expectedSize->getHeight());
     switch ($type) {
         case IMAGETYPE_PNG:
             // integer representation of the color black (rgb: 0,0,0)
             $background = imagecolorallocate($imageCropped, 255, 0, 0);
             // removing the black from the placeholder
             imagecolortransparent($imageCropped, $background);
             // turning off alpha blending (to ensure alpha channel information
             // is preserved, rather than removed (blending with the rest of the
             // image in the form of black))
             imagealphablending($imageCropped, false);
             // turning on alpha channel information saving (to ensure the full range
             // of transparency is preserved)
             imagesavealpha($imageCropped, true);
             break;
         case IMAGETYPE_GIF:
             // integer representation of the color black (rgb: 0,0,0)
             $background = imagecolorallocate($imageCropped, 255, 255, 255);
             // removing the black from the placeholder
             imagecolortransparent($imageCropped, $background);
             break;
     }
     imagecopyresampled($imageCropped, $img, 0, 0, $cropStartX, $cropStartY, $expectedSize->getWidth(), $expectedSize->getHeight(), $expectedSize->getWidth(), $expectedSize->getHeight());
     return $imageCropped;
 }
コード例 #10
0
ファイル: Image.php プロジェクト: sitesupra/sitesupra
 /**
  * Find image size data or create new if not found
  *
  * @param string $sizeName
  * @return ImageSize
  */
 public function getImageSize($sizeName)
 {
     $size = $this->findImageSize($sizeName);
     if (!$size instanceof ImageSize) {
         $size = new ImageSize($sizeName);
         $size->setMaster($this);
     }
     return $size;
 }