コード例 #1
0
ファイル: image.php プロジェクト: egregor-dev/SatCMS
 /**
  * Filter with wideimage (must be installed)
  *  
  * @param mixed $from
  * @param mixed $to
  * @param mixed $format
  */
 static function runWideImage($from, $to, $format)
 {
     if (!class_exists('WideImage')) {
         core::dprint('WideImage not exists!', core::E_CRIT);
         return;
     }
     core::dprint('<<Wideimage ' . __FUNCTION__ . ' ' . join(', ', $format) . ' -- ' . (string) $to, core::E_DEBUG4);
     $image = WideImage::load($from);
     /** @var $converted \WideImage_Image */
     $converted = false;
     $method = array_shift($format);
     /*
     Fatal error: Uncaught exception 'WideImage_Operation_InvalidResizeDimensionException' with message
              'Both dimensions must be larger than 0.' in vendor\spekkionu\wideimage\WideImage\Operation\Resize.php:123
     */
     if (is_callable(array($image, $method))) {
         try {
             $converted = call_user_func_array(array($image, $method), $format);
         } catch (Exception $e) {
             core::dprint(' ..convert image failed: ' . $e->getMessage(), core::E_DEBUG4);
         }
     }
     if ($converted) {
         $converted->saveToFile($to);
     }
 }
コード例 #2
0
 public function editarAction()
 {
     $id = $this->getRequest()->getParam('id');
     $this->view->breadcrumb = array($this->title => 'gestao/banner-home/editar');
     $this->view->rs = $rs = $this->_service->getByid($id);
     if (is_null($rs)) {
         $this->_helper->flashMessenger->addMessage('Operação não permitida!');
         $this->_redirect('/gestao/banner-home/');
     }
     if ($this->_request->isPost()) {
         $data = array('id' => $rs['id'], 'titulo' => $this->_dataPost['titulo'], 'link_saibamais' => $this->_dataPost['link_saibamais'], 'link_reservar' => $this->_dataPost['link_reservar'], 'descricao' => $this->_dataPost['descricao']);
         if ($_FILES['imagem']['name'] != '') {
             require_once '/WideImage/WideImage.php';
             try {
                 $image = WideImage::load('imagem');
             } catch (Exception $e) {
                 $this->_helper->flashMessenger->addMessage('Imagem inválida!');
                 $this->_redirect('/gestao/banner-home');
             }
             $nomeImagem = date('dmYGis');
             $image->saveToFile('img/upload/' . $nomeImagem . '.jpg', 60);
             $image->crop('center', 'center', 920, 650)->saveToFile('img/upload/' . $nomeImagem . '-mobile.jpg', 60);
             $data['imagem'] = 'img/upload/' . $nomeImagem . '.jpg';
             $data['imagem_mobile'] = 'img/upload/' . $nomeImagem . '-mobile.jpg';
             unlink($rs['imagem']);
             unlink($rs['imagem_mobile']);
         }
         $return = $this->_service->update($data);
         if ($return) {
             $this->_helper->flashMessenger->addMessage('Atualizado com sucesso!');
             $this->_redirect('/gestao/banner-home/');
         }
     }
 }
コード例 #3
0
ファイル: applyMask.php プロジェクト: alexyangfox/Filemanager
 function execute($image)
 {
     $mask = WideImage::load(DEMO_PATH . 'masks/' . $this->fields['mask']->value);
     $left = $this->fields['left']->value;
     $top = $this->fields['top']->value;
     return $image->applyMask($mask, $left, $top);
 }
コード例 #4
0
ファイル: UploadBehavior.php プロジェクト: vitorrampazzo/cms
 public function upload(Model $Model, $arquivo = array(), $altura = 800, $largura = 600, $pasta = null, $nome_arquivo)
 {
     // App::uses('Vendor', 'wideimage');
     App::import('Vendor', 'WideImage', array('file' => 'WideImage' . DS . 'WideImage.php'));
     App::uses('Folder', 'Utility');
     $ext = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/x-jps', 'image/png', 'image/gif');
     if ($arquivo['error'] != 0 || $arquivo['size'] == 0) {
         return false;
     }
     $img = WideImage::load($arquivo['tmp_name']);
     $folder = new Folder();
     $pathinfo = pathinfo($arquivo['name']);
     if ($folder->create(WWW_ROOT . 'img' . DS . $pasta . DS)) {
         //se conseguiu criar o diretório eu dou permissão
         $folder->chmod(WWW_ROOT . 'img' . DS . $pasta . DS, 0755, true);
     } else {
         return false;
     }
     $pathinfo['filename'] = strtolower(Inflector::slug($pathinfo['filename'], '-'));
     $arquivo['name'] = $nome_arquivo . '.' . $pathinfo['extension'];
     $img->saveToFile(WWW_ROOT . 'img' . DS . $pasta . DS . 'original_' . $arquivo['name']);
     $img = $img->resize($largura, $altura, 'fill');
     $img->saveToFile(WWW_ROOT . 'img' . DS . $pasta . DS . $arquivo['name']);
     // debug(WWW_ROOT.'img'.DS.$pasta.DS.$arquivo['name']); die;
     return $arquivo['name'];
 }
コード例 #5
0
ファイル: RotateTest.php プロジェクト: NaszvadiG/DivaSul
 function testRotate45()
 {
     $img = WideImage::load(IMG_PATH . '100x100-rainbow.png');
     $new = $img->rotate(45);
     $this->assertEquals(142, $new->getWidth());
     $this->assertEquals(142, $new->getHeight());
 }
コード例 #6
0
ファイル: Evento.php プロジェクト: brunoblauzius/sistema
 /**
  * 
  * @param array $files
  * @param array $post
  */
 public function uploadBanner(array $files, array &$post, $width = 800, $height = 350)
 {
     if (!empty($files) && $files['arquivo']['error'] == 0) {
         try {
             $extensionPermiss = array('jpg', 'jpeg', 'png', 'gif');
             /* codigo de upload */
             if (!file_exists($this->path)) {
                 mkdir($this->path);
             }
             /**
              * Verificar os dados do arquivo
              */
             $fullName = pathinfo($files['arquivo']['name'], PATHINFO_BASENAME);
             $fileName = pathinfo($files['arquivo']['name'], PATHINFO_FILENAME);
             $extension = pathinfo($files['arquivo']['name'], PATHINFO_EXTENSION);
             $pathFile = $this->path . DS . URL::sanitizeTitleWithDashes($fileName) . '.' . $extension;
             if (in_array(strtolower($extension), $extensionPermiss)) {
                 require_once "Library/wideimage/WideImage.php";
                 WideImage::load($files['arquivo']['tmp_name'])->resize($width, $height, 'outside')->saveToFile($pathFile, 90);
                 $post['imagem'] = URL::sanitizeTitleWithDashes($fileName) . '.' . $extension;
             } else {
                 throw new Exception('é permitido somente arquivos do tipo ' . join(',', $extensionPermiss));
             }
         } catch (Exception $ex) {
             throw $ex;
         }
     }
 }
コード例 #7
0
ファイル: imager.php プロジェクト: kyrst/base
 public function display($filename, $setting_index = 0)
 {
     if (!file_exists($filename)) {
         throw new Exception('Image <code>' . $filename . '</code> could not be found.');
     }
     // Get size
     if (isset($this->settings[$setting_index])) {
         $setting = $this->settings[$setting_index];
     } else {
         $setting_index = 0;
         $setting = NULL;
     }
     $cache_filename = $this->cache_dir . md5($filename . $setting_index);
     // Remove cache
     if (file_exists($cache_filename) && (filectime($filename) > filectime($cache_filename) || self::FORCE_GENERATE_CACHE)) {
         unlink($cache_filename);
     }
     // Generate image and cache
     if (!file_exists($cache_filename)) {
         $img = $this->generateCache($filename, $cache_filename, $setting);
     } else {
         $img = WideImage::load($cache_filename);
     }
     // Display
     if ($setting) {
         $img->output($setting['format'], $setting['quality']);
     } else {
         $img->output(self::DEFAULT_FORMAT, self::DEFAULT_QUALITY);
     }
     $img->destroy();
 }
コード例 #8
0
ファイル: Crop.php プロジェクト: FabiolaBraga/kandaframework
 /**
 * @public
 * 
 * @param array $param Valores das variáveis
 * 
 * @example $this->WideImageOne($param = array(
  'Path'=>  array($this->getPathFile('destaque')), //Destino
  'Name'=>$_POST['nome'], //Nome da Foto
  'Size'=>array('239x239'), //Tamanho da Foto
  'File'=>'foto',             //Nome do $_FILES
  //'Delete'=>$foto['foto'], //Deve ser usando quando for upadte
  ));
 * 
 * @return string Retorna o nome da foto
 */
 public function WideImageOne($param)
 {
     self::extensions('wideImage.lib.WideImage');
     $file = $_FILES[$param['File']];
     $type = explode('/', $file['type']);
     $name = $this->caracteres($param['Name'] . '-' . rand(1, 300) . '.' . $type[1]);
     $i = 0;
     $count = count($param['Path']);
     while ($i < $count) {
         if (!is_dir($param['Path'][$i])) {
             echo "Path \n{$param['Path'][$i]}\n naõ encotrado";
             die;
         }
         if (isset($param['Delete']) && !empty($param['Delete'])) {
             if (!$this->WideImageDelete(array('Path' => $param['Path'][$i], 'Name' => $param['Delete']))) {
                 echo '';
             }
         }
         $_load = WideImage::load($file['tmp_name']);
         $size = explode('x', $param['Size'][$i]);
         $_resize = $_load->resize((int) $size[0], (int) $size[1]);
         $_resize->saveToFile($param['Path'][$i] . $name);
         unset($_load, $_resize);
         chmod($param['Path'][$i] . $name, 775);
         ++$i;
     }
     return $name;
 }
コード例 #9
0
ファイル: merge.php プロジェクト: AmandaNatallie/RequisitosPA
 function execute($image, $request)
 {
     $overlay = WideImage::load(DEMO_PATH . 'images/' . $this->fields['overlay']->value);
     $left = $this->fields['left']->value;
     $top = $this->fields['top']->value;
     $opacity = $this->fields['opacity']->value;
     return $image->merge($overlay, $left, $top, $opacity);
 }
コード例 #10
0
 function test()
 {
     $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
     $result = $img->correctGamma(1, 2);
     $this->assertTrue($result instanceof WideImage_PaletteImage);
     $this->assertTrue($result->isTransparent());
     $this->assertEquals(100, $result->getWidth());
     $this->assertEquals(100, $result->getHeight());
 }
コード例 #11
0
 public function cria()
 {
     if (!empty($_GET['idCamp'])) {
         $_SESSION['idCamp'] = $_GET['idCamp'];
     }
     if (isset($_SESSION['idCamp'])) {
         $dados = $dados2 = $dados4 = $this->db->get_where('campanha', array('id' => $_SESSION['idCamp']))->row_array(0);
         $dados3 = array();
         $emp = str_replace(";", ",", $dados['empreendimento']);
         if ($emp != "") {
             $dados3 = $this->db->query("SELECT * FROM empreendimento WHERE id IN ({$emp}) ORDER BY empreendimento ASC")->result_array();
         }
         if (count($dados3) > 0) {
             include './application/assets/misc/wideimage/WideImage.php';
             foreach ($dados3 as $d) {
                 $pastaOrigem = '../' . $d['pasta'] . '/galeria';
                 $pastaDest = '../' . $dados['pasta'] . '/galeria';
                 # Copia
                 $origem = $pastaOrigem . "/" . $d['topo'];
                 $destino = $pastaDest . "/preview_" . $d['id'] . '.jpg';
                 copy($origem, $destino);
                 list($width, $height, $type, $attr) = getimagesize($origem);
                 # Resize
                 $img = WideImage::load($destino);
                 $resized = $img->resize(400, null);
                 $resized = $resized->crop('center', 'top', 400, 260);
                 $resized->saveToFile($destino);
                 $img->destroy();
             }
         }
     } else {
         $dados = UtilFunctions::getColunaTable('campanha');
     }
     if (isset($_POST['formSubmit']) && $_POST['formSubmit'] == true) {
         switch ($_POST['passo']) {
             case 1:
                 if ($dados['id'] == "") {
                     $this->create();
                 } else {
                     $this->update();
                 }
                 break;
             case 2:
                 $this->scripts();
                 break;
             case 3:
                 $this->empreendimento();
                 break;
             case 4:
                 $this->video();
                 break;
         }
     }
     $this->load->view('topo');
     $this->load->view(strtolower($this->area) . '/cria', array('dados' => $dados, 'dados2' => isset($dados2) ? $dados2 : "", 'dados3' => isset($dados3) ? $dados3 : "", 'dados4' => isset($dados4) ? $dados4 : ""));
     $this->load->view('rodape');
 }
コード例 #12
0
 function testApplyFilter()
 {
     $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
     $result = $img->applyFilter(IMG_FILTER_EDGEDETECT);
     $this->assertTrue($result instanceof WideImage_TrueColorImage);
     $this->assertTrue($result->isTransparent());
     $this->assertEquals(100, $result->getWidth());
     $this->assertEquals(100, $result->getHeight());
 }
コード例 #13
0
 function testAutocropHalfImageBug()
 {
     $img = WideImage::load(IMG_PATH . '100x100-red-spot-half-cut.png');
     $cropped = $img->autocrop();
     $this->assertTrue($cropped instanceof WideImage_TrueColorImage);
     $this->assertEquals(22, $cropped->getWidth());
     $this->assertEquals(23, $cropped->getHeight());
     $this->assertRGBNear($cropped->getRGBAt(10, 10), 255, 0, 0);
 }
コード例 #14
0
 public function testApplyConvolution()
 {
     $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
     $result = $img->applyConvolution([[2, 0, 0], [0, -1, 0], [0, 0, -1]], 1, 220);
     $this->assertTrue($result instanceof WideImage_TrueColorImage);
     $this->assertTrue($result->isTransparent());
     $this->assertEquals(100, $result->getWidth());
     $this->assertEquals(100, $result->getHeight());
 }
コード例 #15
0
ファイル: image.class.php プロジェクト: salomalo/php-oxygen
 /**
  * Load an image an instanciate a new Image class
  * 
  * @param string $source    Path to the image to load
  * @return Image 
  */
 public static function load($source)
 {
     $instance = parent::load($source);
     $instance->source = $source;
     $instance->basename = basename($source);
     $instance->name = substr($instance->basename, 0, strrpos($instance->basename, '.'));
     $instance->extension = substr($instance->basename, strrpos($instance->basename, '.'));
     return $instance;
 }
コード例 #16
0
 function testTransparentCorner()
 {
     $img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
     $res = $img->roundCorners(30, null, WideImage::SIDE_ALL);
     $this->assertEquals(100, $res->getWidth());
     $this->assertEquals(100, $res->getHeight());
     $this->assertRGBAt($res, 5, 5, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127));
     $this->assertRGBAt($res, 95, 5, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127));
     $this->assertRGBAt($res, 95, 95, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127));
     $this->assertRGBAt($res, 5, 95, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127));
 }
コード例 #17
0
 public function testPreserveTransparency()
 {
     $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
     $this->assertTrue($img->isTransparent());
     $this->assertRGBEqual($img->getTransparentColorRGB(), 255, 255, 255);
     $tc = $img->asTrueColor();
     $this->assertTrue($tc->isTransparent());
     $this->assertRGBEqual($tc->getTransparentColorRGB(), 255, 255, 255);
     $img = $tc->asPalette();
     $this->assertTrue($img->isTransparent());
     $this->assertRGBEqual($img->getTransparentColorRGB(), 255, 255, 255);
 }
コード例 #18
0
 public function testPNGAlpha()
 {
     $img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
     $gray = $img->asGrayscale();
     $this->assertTrue($gray instanceof WideImage_TrueColorImage);
     $this->assertEquals(100, $gray->getWidth());
     $this->assertEquals(100, $gray->getHeight());
     $this->assertRGBNear($gray->getRGBAt(25, 25), 29, 29, 29, 32);
     $this->assertRGBNear($gray->getRGBAt(75, 25), 29, 29, 29, 64);
     $this->assertRGBNear($gray->getRGBAt(75, 75), 29, 29, 29, 96);
     $this->assertRGBNear($gray->getRGBAt(25, 75), 0, 0, 0, 127);
     $this->assertFalse($gray->isTransparent());
 }
コード例 #19
0
ファイル: ApplyMaskTest.php プロジェクト: NaszvadiG/DivaSul
 function testApplyMask()
 {
     $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
     $mask = WideImage::load(IMG_PATH . '75x25-gray.png');
     $result = $img->applyMask($mask);
     $this->assertTrue($result instanceof WideImage_TrueColorImage);
     $this->assertTrue($result->isTransparent());
     $this->assertEquals(100, $result->getWidth());
     $this->assertEquals(100, $result->getHeight());
     $this->assertRGBNear($result->getRGBAt(10, 10), 255, 255, 255);
     $this->assertRGBNear($result->getRGBAt(30, 10), 255, 255, 0, 64);
     $this->assertRGBNear($result->getRGBAt(60, 10), 0, 0, 255, 0);
 }
コード例 #20
0
ファイル: crop_image.library.php プロジェクト: JessicaJAS/pfc
 public function resize()
 {
     foreach ($this->data as $dt) {
         $x = $dt['x'];
         $y = $dt['y'];
         $w = $dt['w'];
         $h = $dt['h'];
         $img = WideImage::load($dt['origem']);
         $img->resize($dt['resizeH'], $dt['resizeW'], "outside");
         $img = $img->saveToFile($dt['destino']);
     }
     unset($this->data);
 }
コード例 #21
0
 function testGetMaskPNGAlpha()
 {
     $img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
     $mask = $img->getMask();
     $this->assertTrue($mask instanceof WideImage_TrueColorImage);
     $this->assertFalse($mask->isTransparent());
     $this->assertEquals(100, $mask->getWidth());
     $this->assertEquals(100, $mask->getHeight());
     $this->assertRGBNear($mask->getRGBAt(25, 25), 192, 192, 192);
     $this->assertRGBNear($mask->getRGBAt(75, 25), 128, 128, 128);
     $this->assertRGBNear($mask->getRGBAt(75, 75), 64, 64, 64);
     $this->assertRGBNear($mask->getRGBAt(25, 75), 0, 0, 0);
 }
コード例 #22
0
ファイル: canvas.php プロジェクト: engcampo/engcampo
function reduzImagem($file_path, $x, $y)
{
    // Chama o arquivo com a classe WideImage
    require_once '/wideimage/WideImage.php';
    try {
        // Carrega a imagem a ser manipulada
        $image = WideImage::load($file_path);
        // Redimensiona a imagem
        $image = $image->resize($x, $y);
        // Salva a imagem em um arquivo
        $image->saveToFile($file_path);
        return 'OK';
    } catch (Exception $e) {
        return 'Message: ' . $file_path . ' - ' . $e->getMessage();
    }
}
コード例 #23
0
 public function image($one, $two = -1)
 {
     if ($two == -1) {
         $DestinationDirectory = 'assets/uploads/authors-images/';
         $image_name = $DestinationDirectory . 'author-' . $one . '.jpg';
         WideImage::load($image_name)->output('jpg', 90);
     } else {
         $array = explode("_", $one);
         $DestinationDirectory = 'assets/uploads/authors-images/';
         $image_name = $DestinationDirectory . 'author-' . $two . '.jpg';
         list($originalWidth, $originalHeight) = getimagesize($image_name);
         $newWidth = $array[1];
         $newHeight = $originalHeight / $originalWidth * $newWidth;
         WideImage::load($image_name)->resize($newWidth, $newHeight)->output('jpg', 90);
     }
 }
コード例 #24
0
ファイル: uploadr.php プロジェクト: acmadi/diantaksi
 /**
  * Attempts to upload a file, adds it to the database and removes other database entries for that file type if they are asked to be removed
  * @param  string  $field             The name of the $_FILES field you want to upload
  * @param  boolean $upload_type       The type of upload ('news', 'gallery', 'section') etc
  * @param  boolean $type_id           The ID of the item (above) that the upload is linked to
  * @param  boolean $remove_existing   Setting this to true will remove all existing uploads of the passed in type (useful for replacing news article images when a new on
  * @param  boolean $title             Sets the title of the upload
  * @param  boolean $path_to_store     Sets the path to the upload (where it should go)
  * @return object                     Returns the upload object so we can work with the uploaded file and details
  */
 public static function upload($details = array())
 {
     $upload_details = array('remove_existing_for_link' => true, 'path_to_store' => path('public') . 'uploads/', 'resizing' => array('small' => array('w' => 200, 'h' => 200), 'thumb' => array('w' => 200, 'h' => 200)));
     if (!empty($details)) {
         $required_keys = array('upload_field_name', 'upload_type', 'upload_link_id', 'title');
         $continue = true;
         foreach ($required_keys as $key) {
             if (!isset($details[$key]) || empty($details[$key])) {
                 Messages::add('error', 'Your upload array details are not complete... please fill this in properly.');
                 $continue = false;
             }
         }
         if ($continue) {
             $configuration = $details + $upload_details;
             $input = Input::file($configuration['upload_field_name']);
             if ($input && $input['error'] == UPLOAD_ERR_OK) {
                 if ($configuration['remove_existing_for_link']) {
                     static::remove($configuration['upload_type'], $configuration['upload_link_id']);
                 }
                 $ext = File::extension($input['name']);
                 $filename = Str::slug($configuration['upload_type'] . '-' . $configuration['upload_link_id'] . '-' . Str::limit(md5($input['name']), 10, false) . '-' . $configuration['title'], '-');
                 Input::upload($configuration['upload_field_name'], $configuration['path_to_store'], $filename . '.' . $ext);
                 $upload = new Upload();
                 $upload->link_type = $configuration['upload_type'];
                 $upload->link_id = $configuration['upload_link_id'];
                 $upload->filename = $filename . '.' . $ext;
                 if (Koki::is_image($configuration['path_to_store'] . $filename . '.' . $ext)) {
                     $upload->small_filename = $filename . '_small' . '.' . $ext;
                     $upload->thumb_filename = $filename . '_thumb' . '.' . $ext;
                     $upload->image = 1;
                 }
                 $upload->extension = $ext;
                 $upload->user_id = Auth::user()->id;
                 $upload->save();
                 if (Koki::is_image($configuration['path_to_store'] . $filename . '.' . $ext)) {
                     WideImage::load($configuration['path_to_store'] . $upload->filename)->resize($configuration['resizing']['small']['w'], $configuration['resizing']['small']['h'])->saveToFile($configuration['path_to_store'] . $upload->small_filename);
                     WideImage::load($configuration['path_to_store'] . $upload->small_filename)->crop('center', 'center', $configuration['resizing']['thumb']['w'], $configuration['resizing']['thumb']['h'])->saveToFile($configuration['path_to_store'] . $upload->thumb_filename);
                 }
                 return true;
             }
         }
     } else {
         Messages::add('error', 'Your upload array details are empty... please fill this in properly.');
     }
     return false;
 }
コード例 #25
0
ファイル: MergeTest.php プロジェクト: doankhoi/Application
 function testMergeOpacityFull()
 {
     $img = WideImage::load(IMG_PATH . '100x100-color-hole.png');
     $overlay = WideImage::load(IMG_PATH . '100x100-square-overlay.png');
     $res = $img->merge($overlay, 0, 0, 100);
     $this->assertEquals(100, $res->getWidth());
     $this->assertEquals(100, $res->getHeight());
     $rgb = $res->getRGBAt(5, 5);
     $this->assertRGBAt($res, 5, 5, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0));
     $this->assertRGBAt($res, 40, 40, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0));
     $this->assertRGBAt($res, 95, 5, array('red' => 0, 'green' => 0, 'blue' => 255, 'alpha' => 0));
     $this->assertRGBAt($res, 60, 40, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
     $this->assertRGBAt($res, 95, 95, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 0));
     $this->assertRGBAt($res, 60, 60, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 0));
     $this->assertRGBAt($res, 5, 95, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 0));
     $this->assertRGBAt($res, 40, 60, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 0));
 }
コード例 #26
0
ファイル: PacotesController.php プロジェクト: pccnf/sitevilla
 public function editarAction()
 {
     //$this->view->headScript()->prependFile($this->view->baseUrl('cms_novo/js/ckeditor/ckeditor.js'));
     $id = $this->getRequest()->getParam('id');
     $this->view->breadcrumb = array($this->title => 'gestao/pacotes/editar');
     $rs = $this->_service->getByid($id);
     $this->view->rs = $rs;
     if (is_null($rs)) {
         $this->_helper->flashMessenger->addMessage('Operação não permitida!');
         $this->_redirect('/gestao/pacotes/');
     }
     if ($this->_request->isPost()) {
         $data = array('id' => $rs['id'], 'titulo' => $this->_dataPost['titulo'], 'descricao' => $this->_dataPost['descricao']);
         if ($_FILES['imagem_destaque']['name'] != '') {
             require_once '/WideImage/WideImage.php';
             try {
                 $image = WideImage::load('imagem_destaque');
             } catch (Exception $e) {
                 $this->_helper->flashMessenger->addMessage('Imagem inválida!');
                 $this->_redirect('/gestao/pacotes');
             }
             $nomeImagem = date('dmYGis');
             $image->saveToFile('img/upload/' . $nomeImagem . '.jpg', 60);
             $data['imagem_destaque'] = 'img/upload/' . $nomeImagem . '.jpg';
             unlink($rs['imagem_destaque']);
         }
         if ($_FILES['banner']['name'] != '') {
             require_once '/WideImage/WideImage.php';
             try {
                 $image = WideImage::load('banner');
             } catch (Exception $e) {
                 $this->_helper->flashMessenger->addMessage('Imagem inválida!');
                 $this->_redirect('/gestao/pacotes');
             }
             $nomeImagem = date('dmYGis');
             $image->saveToFile('img/upload/' . $nomeImagem . '.jpg', 60);
             $data['imagem_destaque'] = 'img/upload/' . $nomeImagem . '-banner-pacotes.jpg';
             unlink($rs['banner']);
         }
         $return = $this->_service->update($data);
         if ($return) {
             $this->_helper->flashMessenger->addMessage('Atualizado com sucesso!');
             $this->_redirect('/gestao/pacotes/');
         }
     }
 }
コード例 #27
0
ファイル: function.smartcrop.php プロジェクト: xhat/smartcrop
function smart_crop($file, $saveAs = NULL, $width = 100, $height = 100)
{
    if (!class_exists('WideImage')) {
        die('"smart_crop" requires "WideImage Library" to be included.');
    }
    if ($saveAs == NULL) {
        $saveAs = $file;
    }
    list($w, $h) = getimagesize($file);
    $wpercent = $w / $width * 100;
    $hpercent = $h / $height * 100;
    $img = WideImage::load($file);
    if ($wpercent >= 100 && $hpercent >= 100) {
        // Both is over 100% of the allowed size, then resize so the smalle side match.
        if ($wpercent > $hpercent) {
            // height is smallest
            $remove_percent = $hpercent - 100;
        } else {
            // width is smallest
            $remove_percent = $wpercent - 100;
        }
        $new_h_percent = $hpercent - $remove_percent;
        $new_w_percent = $wpercent - $remove_percent;
        $new_w = $width * (1 + ($new_w_percent - 100));
        $new_h = $height * (1 + ($new_h_percent - 100));
        $img = $img->resize($new_w, $new_h, 'inside');
        $img = $img->crop("center", "middle", $width, $height);
    } else {
        // One of them is smaller than 100% of the allowed size
        if ($wpercent > $hpercent) {
            // height is smallest
            $add_percent = 100 - $hpercent;
        } else {
            // width is smallest
            $add_percent = 100 - $wpercent;
        }
        $new_h_percent = $hpercent + $add_percent;
        $new_w_percent = $wpercent + $add_percent;
        $new_w = $width * (1 + ($new_w_percent - 100));
        $new_h = $height * (1 + ($new_h_percent - 100));
        $img = $img->resize($new_w, $new_h, 'inside');
        $img = $img->crop("center", "middle", $width, $height);
    }
    $img->saveToFile($saveAs);
}
コード例 #28
0
ファイル: index.php プロジェクト: PotsonHumer/OGS_V2
 function __construct($src)
 {
     require ROOT_PATH . '/watermark/WideImage.php';
     $watermark = WideImage::load(ROOT_PATH . '/watermark/watermark.png');
     //浮水印圖片尺寸
     $origin_width = $watermark->getWidth();
     $origin_height = $watermark->getHeight();
     $base = WideImage::load($src);
     $sw = 1;
     //0:高度優先,1:寬度優先
     if ($sw) {
         $target_width = round($base->getWidth() * 0.8, 0);
         if ($target_width < $origin_width) {
             $water_width = $target_width;
             $watermark = $watermark->resize($water_width);
             $water_height = $watermark->getHeight();
         } else {
             $water_width = $origin_width;
             $water_height = $origin_height;
         }
     } else {
         $target_height = round($base->getHeight() / 4, 0);
         if ($target_height < $origin_height) {
             $water_height = $target_height;
             $watermark = $watermark->resize(null, $water_height);
             $water_width = $watermark->getWidth();
         } else {
             $water_width = $origin_width;
             $water_height = $origin_height;
         }
     }
     $dest_x = round(($base->getWidth() - $water_width) / 2, 0);
     $dest_y = round(($base->getHeight() - $water_height) / 2, 0);
     $res = $base->merge($watermark, $dest_x, $dest_y);
     if (eregi('.gif', $src)) {
         $res->output('gif');
     } elseif (eregi('.jpeg', $src) || eregi('.jpg', $src)) {
         $res->output('jpg');
     } elseif (eregi('.png', $src)) {
         $res->output('png');
     }
     $base->destroy();
     $watermark->destroy();
     $res->destroy();
 }
コード例 #29
0
ファイル: MirrorTest.php プロジェクト: thaida/CMS
 function testMirror()
 {
     $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
     $this->assertRGBEqual($img->getRGBAt(5, 5), 255, 255, 0);
     $this->assertRGBEqual($img->getRGBAt(95, 5), 0, 0, 255);
     $this->assertRGBEqual($img->getRGBAt(95, 95), 0, 255, 0);
     $this->assertRGBEqual($img->getRGBAt(5, 95), 255, 0, 0);
     $new = $img->mirror();
     $this->assertTrue($new instanceof WideImage_PaletteImage);
     $this->assertEquals(100, $new->getWidth());
     $this->assertEquals(100, $new->getHeight());
     $this->assertRGBEqual($new->getRGBAt(95, 5), 255, 255, 0);
     $this->assertRGBEqual($new->getRGBAt(5, 5), 0, 0, 255);
     $this->assertRGBEqual($new->getRGBAt(5, 95), 0, 255, 0);
     $this->assertRGBEqual($new->getRGBAt(95, 95), 255, 0, 0);
     $this->assertTrue($new->isTransparent());
     $this->assertRGBEqual($new->getRGBAt(50, 50), $img->getTransparentColorRGB());
 }
コード例 #30
-1
ファイル: Imagem.php プロジェクト: sgdoc/sgdoce-codigo
 /**
  * Metdo responsavel por persistir os uploads
  * @param type $destino
  * @param type $thumb
  * @param type $validFile
  * @param type $invalidFile
  * @return type
  */
 public static function upload($destino = 'anexoArtefato', $thumb = FALSE, $validFile = TRUE, $invalidFile = TRUE, $validImageSize = TRUE)
 {
     $configs = \Core_Registry::get('configs');
     $upload = new \Zend_File_Transfer_Adapter_Http();
     $files = $upload->getFileInfo();
     $filesUp = array();
     $return = array();
     $error = false;
     $pasta = 'anexo-material';
     if ($destino == 'anexoArtefato') {
         $pasta = 'anexo-artefato';
     }
     $path = current(explode('application', __DIR__)) . 'data' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $pasta . DIRECTORY_SEPARATOR;
     foreach ($files as $file => $info) {
         $upload = new \Zend_File_Transfer_Adapter_Http();
         $upload->setDestination($path);
         $upload->setValidators(array());
         $upload->addValidator('Size', TRUE, array('max' => '100MB', 'messages' => "O tamanho do arquivo é superior ao permitido. O tamanho permitido é 100MB."));
         self::_invalidFile($invalidFile, $upload);
         self::_validFile($validFile, $upload);
         self::_validImageSize($validImageSize, $upload);
         self::_getValidator($upload);
         if ($upload->isValid($file)) {
             $fileinfo = pathinfo($info['name']);
             $upload->receive($file);
             $filesUp[] = $upload->getFileName($file);
             $return[] = array('name' => $upload->getFileName($file), 'size' => $upload->getFileSize($file));
         } else {
             $error = $upload->getMessages();
             break;
         }
     }
     if ($error) {
         if (count($filesUp)) {
             foreach ($filesUp as $file) {
                 unlink($file);
             }
         }
         return array('errors' => $error);
     }
     if ($thumb) {
         $pasta = current(explode('application', __DIR__)) . 'data' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR;
         foreach ($filesUp as $endereco) {
             $fileinfo = pathinfo($endereco);
             $image = \WideImage::load($endereco);
             $image->resize(300, 300, 'outside')->crop('50% - 150', '50% - 150', 300, 300)->saveToFile($pasta . $fileinfo['filename'] . '_300_X_300.' . strtolower($fileinfo['extension']));
             $image->resize(133, 89, 'outside')->crop('50% - 67', '50% - 45', 133, 89)->saveToFile($pasta . $fileinfo['filename'] . '_133_X_89.' . strtolower($fileinfo['extension']));
         }
     }
     return $return;
 }