예제 #1
0
파일: resize.php 프로젝트: 4johndoe/shop
<?php

include '../../application/libraries/SimpleImage.php';
$cat = 'tees/';
$oridir = "../jack/" . $cat;
$files = array();
$dir = opendir($oridir);
// open the cwd..also do an err check.
while (false != ($file = readdir($dir))) {
    if ($file != "." and $file != ".." and $file != "index.php") {
        $files[] = $file;
        // put in array.
    }
}
natsort($files);
// sort.
// print.
foreach ($files as $file) {
    $ori = $oridir . $file;
    // echo("<a href='$file'>$file</a> <br />\n");
    try {
        $img = new abeautifulsite\SimpleImage($ori);
        $img->resize(460, 460)->save($cat . $file);
    } catch (Exception $e) {
        echo 'Error: ' . $e->getMessage();
    }
}
예제 #2
0
 public function createVersion($imagePath, $sizeString = false, $crop = true, $fitImageInCanvas = false)
 {
     if (strlen($this->urlAlias) < 1) {
         throw new \Exception('Image without urlAlias!');
     }
     $cachePath = $this->getModule()->getCachePath();
     $subDirPath = $this->getSubDur();
     $fileExtension = pathinfo($this->filePath, PATHINFO_EXTENSION);
     if ($sizeString) {
         $sizePart = '_' . $sizeString;
     } else {
         $sizePart = '';
     }
     $pathToSave = $cachePath . '/' . $subDirPath . '/' . $this->urlAlias . $sizePart . '.' . $fileExtension;
     BaseFileHelper::createDirectory(dirname($pathToSave), 0777, true);
     if ($sizeString) {
         $size = $this->getModule()->parseSize($sizeString);
     } else {
         $size = false;
     }
     if ($this->getModule()->graphicsLibrary == 'Imagick') {
         // Fixes interlaced images
         $interlaceFix = $this->interlaceFix($imagePath);
         if ($interlaceFix) {
             $image = new \Imagick();
             $image->readImageBlob($interlaceFix);
         } else {
             $image = new \Imagick($imagePath);
         }
         $image->setImageCompressionQuality(100);
         // Fixes image rotations
         $this->ImagickAutoRotateImage($image);
         // If the dimensions of the original image match the requested
         // dimensions the original image is just copied to the new path
         if ($image->getImageWidth() == $size['width'] && $image->getImageHeight() == $size['height']) {
             copy($imagePath, $pathToSave);
             return $image;
         }
         if ($size) {
             if ($size['height'] && $size['width']) {
                 if (!$crop && $fitImageInCanvas) {
                     $image = $this->fitImageInCanvas($image, $size['width'], $size['height']);
                 } elseif ($crop) {
                     $image->cropThumbnailImage($size['width'], $size['height']);
                 } else {
                     $image->resizeImage($size['width'], $size['height'], \Imagick::FILTER_HAMMING, 1, false);
                 }
             } elseif ($size['height']) {
                 $image->thumbnailImage(0, $size['height']);
             } elseif ($size['width']) {
                 $image->thumbnailImage($size['width'], 0);
             } else {
                 throw new \Exception('Something wrong with this->module->parseSize($sizeString)');
             }
         }
         $image->writeImage($pathToSave);
     } else {
         $image = new \abeautifulsite\SimpleImage($imagePath);
         // If the dimensions of the original image match the requested
         // dimensions the original image is just copied to the new path
         if ($image->get_width() == $size['width'] && $image->get_height() == $size['height']) {
             copy($imagePath, $pathToSave);
             return $image;
         }
         if ($size) {
             if ($size['height'] && $size['width']) {
                 if ($crop) {
                     $image->thumbnail($size['width'], $size['height']);
                 } else {
                     $image->resize($size['width'], $size['height']);
                 }
             } elseif ($size['height']) {
                 $image->fit_to_height($size['height']);
             } elseif ($size['width']) {
                 $image->fit_to_width($size['width']);
             } else {
                 throw new \Exception('Something wrong with this->module->parseSize($sizeString)');
             }
         }
         //WaterMark
         if ($this->getModule()->waterMark) {
             if (!file_exists(Yii::getAlias($this->getModule()->waterMark))) {
                 throw new Exception('WaterMark not detected!');
             }
             $wmMaxWidth = intval($image->get_width() * 0.4);
             $wmMaxHeight = intval($image->get_height() * 0.4);
             $waterMarkPath = Yii::getAlias($this->getModule()->waterMark);
             $waterMark = new \abeautifulsite\SimpleImage($waterMarkPath);
             if ($waterMark->get_height() > $wmMaxHeight or $waterMark->get_width() > $wmMaxWidth) {
                 $waterMarkPath = $this->getModule()->getCachePath() . DIRECTORY_SEPARATOR . pathinfo($this->getModule()->waterMark)['filename'] . $wmMaxWidth . 'x' . $wmMaxHeight . '.' . pathinfo($this->getModule()->waterMark)['extension'];
                 //throw new Exception($waterMarkPath);
                 if (!file_exists($waterMarkPath)) {
                     $waterMark->fit_to_width($wmMaxWidth);
                     $waterMark->save($waterMarkPath, 100);
                     if (!file_exists($waterMarkPath)) {
                         throw new Exception('Cant save watermark to ' . $waterMarkPath . '!!!');
                     }
                 }
             }
             $image->overlay($waterMarkPath, 'bottom right', 0.5, -10, -10);
         }
         $image->save($pathToSave, 100);
     }
     return $image;
 }
예제 #3
0
    $command[] = '"' . $thumb->destination->root . '"';
    exec(implode(' ', $command));
};
/**
 * GDLib Driver
 */
thumb::$drivers['gd'] = function ($thumb) {
    try {
        $img = new abeautifulsite\SimpleImage($thumb->root());
        $img->quality = $thumb->options['quality'];
        if ($thumb->options['crop']) {
            @$img->thumbnail($thumb->options['width'], $thumb->options['height']);
        } else {
            $dimensions = clone $thumb->source->dimensions();
            $dimensions->fitWidthAndHeight($thumb->options['width'], $thumb->options['height'], $thumb->options['upscale']);
            @$img->resize($dimensions->width(), $dimensions->height());
        }
        if ($thumb->options['grayscale']) {
            $img->desaturate();
        }
        if ($thumb->options['blur']) {
            $img->blur('gaussian', $thumb->options['blurpx']);
        }
        if ($thumb->options['autoOrient']) {
            $img->auto_orient();
        }
        @$img->save($thumb->destination->root);
    } catch (Exception $e) {
        $thumb->error = $e;
    }
};
 /**
  * Update Table Map
  */
 public function editTableMapAction()
 {
     // get Current user
     $user = $this->container->get('security.context')->getToken()->getUser();
     // Check if user auth in app
     if (!is_object($user) || !$user instanceof UserInterface) {
         throw new AccessDeniedException("Access denied");
     }
     // collect data
     $tableMapId = $this->getRequest()->request->get('tableMapId');
     $floor = $this->getRequest()->request->get('mapFloor');
     $file = $this->getRequest()->files->get('mapFile');
     $mapHall = $this->getRequest()->request->get('mapHall');
     // init table Map
     $tableMap = $this->getTableMapManager()->findOneById($tableMapId);
     $tableMap->setFloor($floor);
     if (!is_null($mapHall)) {
         $tableMap->setHall($mapHall);
     }
     // Update file if isset
     if (!is_null($file)) {
         $tableMap->setFile($file);
     }
     $em = $this->getDoctrine()->getManager();
     $em->persist($tableMap);
     $em->flush();
     if (!is_null($file)) {
         // resize image
         $helper = $this->container->get('vich_uploader.templating.helper.uploader_helper');
         $imagePath = getcwd() . $helper->asset($tableMap, 'table_map');
         // check if file exist
         if (file_exists($imagePath) && getimagesize($imagePath)) {
             // resize (BIG versio)
             // Get bigImagePath
             $bigImagePath = str_replace($tableMap->getFileName(), $tableMap->getBigFileName(), $imagePath);
             $resizedBigImage = new \abeautifulsite\SimpleImage($imagePath);
             $resizedBigImage->resize(TableMap::IMAGE_WIDTH_BIG, TableMap::IMAGE_HEIGHT_BIG)->save($bigImagePath);
             $resizedImage = new \abeautifulsite\SimpleImage($imagePath);
             $resizedImage->resize(TableMap::IMAGE_WIDTH, TableMap::IMAGE_HEIGHT)->save($imagePath);
         } else {
             // delete entity
             // $em->remove($tableMap);
             // $em->flush();
         }
     }
     return $this->redirect($this->generateUrl("table_viewCreateMap", array("restaurantId" => $tableMap->getRestaurant()->getId())) . "?mapId={$tableMapId}");
 }