function testRotate45() { $img = wiImage::load(IMG_PATH . '100x100-rainbow.png'); $new = $img->rotate(45); $this->assertEqual(142, $new->getWidth()); $this->assertEqual(142, $new->getHeight()); }
function testCopyCombinedChannels() { $img = wiImage::load(IMG_PATH . '100x100-blue-alpha.png'); $copy = $img->getChannels('blue', 'alpha'); $this->assertRGBNear($copy->getRGBAt(25, 25), 0, 0, 255, 0.25 * 127); $this->assertRGBNear($copy->getRGBAt(75, 25), 0, 0, 255, 0.5 * 127); $this->assertRGBNear($copy->getRGBAt(75, 75), 0, 0, 255, 0.75 * 127); $this->assertRGBNear($copy->getRGBAt(25, 75), 0, 0, 0, 127); }
function testCropPNGAlpha() { $img = wiImage::load(IMG_PATH . '100x100-blue-alpha.png'); $cropped = $img->crop(10, 10, 50, 50); $this->assertTrue($cropped instanceof wiTrueColorImage); $this->assertFalse($cropped->isTransparent()); $this->assertEqual(50, $cropped->getWidth()); $this->assertEqual(50, $cropped->getHeight()); $this->assertRGBNear($cropped->getRGBAt(39, 39), 0, 0, 255, 32); $this->assertRGBNear($cropped->getRGBAt(40, 40), 0, 0, 255, 96); }
function redimensionaImg($original, $destino, $width, $height, $fit, $scale, $qualidade = 90) { $imagem = wiImage::load($original); if ($imagem->getWidth() > $width || $imagem->getHeight() > $height) { $imagem->resize($width, $height, $fit, $scale)->saveToFile($destino, null, $qualidade); } else { if (file_exists($destino)) { JFile::delete($destino); } } }
public function getResizedWebPath($width = null, $height = null) { $resizedPath = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfTinyMceImageBrowser_directory', 'sfTinyMceImageBrowser') . DIRECTORY_SEPARATOR . $this->getResizedFileName($width, $height); if (!file_exists($resizedPath) && ($width || $height)) { $wiImage = wiImage::load($this->getLocalPath())->resize($width, $height, 'outside'); if ($width && $height) { $wiImage = $wiImage->crop(round(($wiImage->getWidth() - $width) / 2), round(($wiImage->getHeight() - $height) / 2), $width, $height); } $wiImage->saveToFile($resizedPath, 'jpeg', 80); } return str_replace(DIRECTORY_SEPARATOR, '/', str_replace(sfConfig::get('sf_web_dir'), '', $resizedPath)); }
function testPNGAlpha() { $img = wiImage::load(IMG_PATH . '100x100-blue-alpha.png'); $gray = $img->asGrayscale(); $this->assertTrue($gray instanceof wiTrueColorImage); $this->assertEqual(100, $gray->getWidth()); $this->assertEqual(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()); }
function testApplyMask() { $img = wiImage::load(IMG_PATH . '100x100-color-hole.gif'); $mask = wiImage::load(IMG_PATH . '75x25-gray.png'); $result = $img->applyMask($mask); $this->assertTrue($result instanceof wiTrueColorImage); $this->assertTrue($result->isTransparent()); $this->assertEqual(100, $result->getWidth()); $this->assertEqual(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); }
function testResizeInside() { $img = wiImage::load(IMG_PATH . '100x100-color-hole.gif'); $resized = $img->resize(50, 20, 'inside'); $this->assertTrue($resized instanceof wiTrueColorImage); $this->assertTrue($resized->isTransparent()); $this->assertEqual(20, $resized->getWidth()); $this->assertEqual(20, $resized->getHeight()); /* $this->assertRGBEqual($resized->getRGBAt(5, 5), 255, 255, 0); $this->assertRGBEqual($resized->getRGBAt(45, 5), 0, 0, 255); $this->assertRGBEqual($resized->getRGBAt(45, 15), 0, 255, 0); $this->assertRGBEqual($resized->getRGBAt(5, 15), 255, 0, 0); $this->assertRGBEqual($resized->getRGBAt(25, 10), 255, 255, 255); $this->assertRGBEqual($img->getTransparentColorRGB(), 255, 255, 255); */ }
function testMirror() { $img = wiImage::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 wiPaletteImage); $this->assertEqual(100, $new->getWidth()); $this->assertEqual(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()); }
function testAsTrueColor() { $img = wiImage::load(IMG_PATH . '100x100-color-hole.gif'); $this->assertTrue($img instanceof wiPaletteImage); $this->assertTrue($img->isValid()); $copy = $img->asTrueColor(); $this->assertFalse($img->getHandle() === $copy->getHandle()); $this->assertTrue($copy instanceof wiTrueColorImage); $this->assertTrue($copy->isValid()); $this->assertTrue($copy->isTrueColor()); $this->assertTrue($copy->isTransparent()); $this->assertRGBEqual($copy->getRGBAt(15, 15), 255, 255, 0); $this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 255); $this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 255, 0); $this->assertRGBEqual($copy->getRGBAt(15, 85), 255, 0, 0); $this->assertEqual($copy->getRGBAt(50, 50), $copy->getTransparentColorRGB()); $rgb = $copy->getTransparentColorRGB(); $this->assertRGBEqual($img->getTransparentColorRGB(), $rgb['red'], $rgb['green'], $rgb['blue']); }
protected function doSave($con = null) { $file = $this->getValue('file'); $filename = sha1($file->getOriginalName() . time()) . $file->getExtension($file->getOriginalExtension()); $filePath = sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_sfTinyMceImageBrowserPlugin_directory', 'sfTinyMceImageBrowser') . '/' . $filename; $file->save($filePath); if (sfConfig::get('app_sfTinyMceImageBrowserPlugin_allow_resize', true)) { $width = $this->getValue('width') ? $this->getValue('width') : null; $height = $this->getValue('height') ? $this->getValue('height') : null; if ($width || $height) { $fit = $width && $height ? 'outside' : 'inside'; $wiImage = wiImage::load($filePath)->resize($width, $height, $fit); if ($width && $height) { $wiImage = $wiImage->crop(round(($wiImage->getWidth() - $width) / 2), round(($wiImage->getHeight() - $height) / 2), $width, $height); } $wiImage->saveToFile($filePath, substr($file->getExtension(), 1)); } } return parent::doSave($con); }
function salvar() { require_once ECOMP_PATH_CLASS . DS . 'wideimage' . DS . 'lib' . DS . 'WideImage.inc.php'; // carrega o post $dados = $_POST; $idcomponente = JRequest::getVar('idcomponente', 0); $idcadastro = JRequest::getVar('idcadastro', 0); $path_dest = ECOMP_PATH_IMAGENS; $file = JRequest::getVar('Filedata', null, 'files', 'array'); $file_name = JFile::makeSafe($file['name']); $file_ext = strtolower(JFile::getExt($file_name)); $file_tmp = $file['tmp_name']; if ($file_ext != 'png') { $file_ext = 'jpg'; } $js = JRequest::getVar('js', 0); // remove variaveis inuteis unset($dados['Filedata'], $dados['Filename'], $dados['sid'], $dados['task'], $dados['view'], $dados['option'], $dados['js'], $dados['Upload'], $dados['layout']); // carrega os dados $imagem = new JCRUD(ECOMP_TABLE_CADASTROS_IMAGENS, $dados); if ($imagem->id) { $imagem->update(); } else { $imagem->insert(); } if ($file['error'] != 4) { $file_dest = $path_dest . DS . $imagem->id . '.' . $file_ext; $file_new = $path_dest . DS . $imagem->id . '.redimensionada.' . $file_ext; $file_db = $imagem->id . '.' . $file_ext; $file_p = $path_dest . DS . $imagem->id . '_p.jpg'; $file_m = $path_dest . DS . $imagem->id . '_m.jpg'; //die(print_r($file , true)); if (JFile::upload($file_tmp, $file_dest)) { if ($file_ext != 'png') { wiImage::load($file_dest)->resize(1024, 1024, 'inside', 'down')->saveToFile($file_new, null, 90); // Cria imagem 800x600 //$file_800 = $path_dest.DS.$imagem->id.'_800x600.jpg'; //ecompHelper::redimensionaImg($file_new, $file_800, 800, 600, 'inside', 'down', 90); // Cria imagem 640x480 //$file_640 = $path_dest.DS.$imagem->id.'_640x480.jpg'; //ecompHelper::redimensionaImg($file_new, $file_640, 640, 480, 'inside', 'down', 90); // Cria imagem 320x240 //$file_320 = $path_dest.DS.$imagem->id.'_320x240.jpg'; //ecompHelper::redimensionaImg($file_new, $file_320, 320, 240, 'inside', 'down', 90); } else { JFile::copy($file_dest, $file_new); } // apaga a imagem grande unlink($file_dest); // se o nome do arquivo cadastro anteriormente for diferente if ($imagem->file != $file_db) { // apaga o arquivo velhos @unlink($path_dest . DS . $imagem->file); @unlink($file_p); @unlink($file_m); } // renomeia a imagem redimencionada pela o destino JFile::move($file_new, $file_dest); // cria a imagem mini wiImage::load($file_dest)->resize(100, 100, 'inside', 'down')->saveToFile($file_p, null, 90); // cria a imagem mini wiImage::load($file_dest)->resize(250, 250, 'inside', 'down')->saveToFile($file_m, null, 90); // muda o nome do arquivo no banco $imagem->file = $file_db; // atualiza o banco de dados $imagem->update(); } } // se o post for enviado por js if ($js == "1") { echo 'texto de ok!'; jexit(); } return true; }
/** * Resize a Picture to some given dimensions (using the wideImage library) * * @param string $src_path Picture's source * @param string $dst_path Picture's destination * @param integer $param_width Maximum picture's width * @param integer $param_height Maximum picture's height * @param boolean $keep_original Do we have to keep the original picture ? * @param string $fit Resize mode (see the wideImage library for more information) */ function resizePicture($src_path, $dst_path, $param_width, $param_height, $keep_original = false, $fit = 'inside') { require_once OLEDRION_PATH . 'class/wideimage/WideImage.inc.php'; $resize = true; if (OLEDRION_DONT_RESIZE_IF_SMALLER) { $pictureDimensions = getimagesize($src_path); if (is_array($pictureDimensions)) { $width = $pictureDimensions[0]; $height = $pictureDimensions[1]; if ($width < $param_width && $height < $param_height) { $resize = false; } } } $img = wiImage::load($src_path); if ($resize) { $result = $img->resize($param_width, $param_height, $fit); $result->saveToFile($dst_path); } else { @copy($src_path, $dst_path); } if (!$keep_original) { @unlink($src_path); } return true; }
/** This file is part of WideImage. WideImage is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. WideImage is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with WideImage; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA **/ require_once dirname(__FILE__) . '/helpers/common.inc.php'; $img = wiImage::load(WI_IMG_PATH . Request::get('img')); $overlay = wiImage::load(WI_IMG_PATH . Request::get('overlay')); $pct = Request::getInt('pct', 50); if ($pct < 0) { $pct = 0; } if ($pct > 100) { $pct = 100; } $result = $img->merge($overlay, 25, 20, $pct); $format = substr(Request::get('img'), -3); img_header($format); echo $result->asString('jpeg');
function salvar() { require_once ECOMP_PATH_CLASS . DS . 'ebasic.util.php'; require_once ECOMP_PATH_CLASS . DS . 'wideimage' . DS . 'lib' . DS . 'WideImage.inc.php'; $idcomponente = JRequest::getVar('idcomponente', 0); $post = $_POST; $dados = array('id' => $post['id'], 'published' => $post['published'], 'ordering' => $post['ordering']); foreach ($post['dados'] as $idcampo => $v) { // abre o campo $campo = new JCRUD(ECOMP_TABLE_CAMPOS, array('id' => $idcampo)); $coluna = key($v); $valor = str_replace('$id', $post['id'], stripslashes($v[$coluna])); $dados[$coluna] = $valor; //data if ($campo->idtipo == 6) { $dados[$coluna] = eUtil::converteData($valor); } } // abre o componente $componente = new JCRUD(ECOMP_TABLE_COMPONENTES, array('id' => $idcomponente)); // abre o cadastro $cadastro = new JCRUD(ECOMP_TABLE_COMPONENTES . "_{$componente->alias}", $dados); // apaga o relacionamento antigo com as tags e categorias JCRUD::query("DELETE FROM " . ECOMP_TABLE_CADASTROS_TAGS . " WHERE idcomponente = '{$idcomponente}' AND idcadastro = {$cadastro->id}"); JCRUD::query("DELETE FROM " . ECOMP_TABLE_CADASTROS_CATEGORIAS . " WHERE idcomponente = '{$idcomponente}' AND idcadastro = {$cadastro->id}"); // if ($cadastro->id) { $cadastro->update(); } else { $cadastro->insert(); } // cadastra as tags $tags = new JCRUD(ECOMP_TABLE_CADASTROS_TAGS); if (isset($post['tags'])) { foreach ($post['tags'] as $tag) { $tags->id = null; $tags->idcomponente = $idcomponente; $tags->idcadastro = $cadastro->id; $tags->idtag = $tag; $tags->insert(); } } // cadastra as categorias $categorias = new JCRUD(ECOMP_TABLE_CADASTROS_CATEGORIAS); if (isset($post['categorias'])) { foreach ($post['categorias'] as $cat) { $categorias->id = null; $categorias->idcomponente = $idcomponente; $categorias->idcadastro = $cadastro->id; $categorias->idcategoria = $cat; $categorias->insert(); } } //////////////////////////////////////////////////// // uploads //////////////////////////////////////////////////// $uploads = count($_FILES['dados']) ? $_FILES['dados'] : array(); foreach ($uploads['name'] as $idcampo => $coluna) { $campo = new JCRUD(ECOMP_TABLE_CAMPOS, array('id' => $idcampo)); $coluna = key($coluna); $tipo = new JCRUD(ECOMP_TABLE_TIPOS, array('id' => $campo->idtipo)); parse_str($tipo->params, $params1); parse_str($campo->params, $params2); $params = array_merge($params1, $params2); //upload de imagem if ($campo->idtipo == 11 && $uploads['error'][$idcampo][$coluna] != 4) { $path_dest = ECOMP_PATH_UPLOADS . DS . $idcomponente . DS . $cadastro->id; $file = $uploads; $file_ext = strtolower(JFile::getExt($file['name'][$idcampo][$coluna])); $file_name = $coluna . '.' . $file_ext; $file_tmp = $file['tmp_name'][$idcampo][$coluna]; $file_dest = $path_dest . DS . $file_name; if (strpos($params['ext'], $file_ext) !== false) { // eLoad - Salva o caminho da pasta cache atual if (file_exists($file_dest)) { $cache_dir = ECOMP_PATH_CACHE_ELOAD . DS . substr(sha1_file($file_dest), 0, 10); } if (JFile::upload($file_tmp, $file_dest)) { // eLoad - Apaga a pasta cache anterior if (isset($cache_dir) && is_dir($cache_dir)) { JFolder::delete($cache_dir); } // apaga o arquivo if ($cadastro->{$coluna} != $file_name) { @unlink($path_dest . DS . $cadastro->{$coluna}); } if ($params['resize'] == 1) { if ($file_ext != 'gif' || $file_ext == 'gif' && $params['resize_gif'] == 1) { $imagem = wiImage::load($file_dest); if ($imagem->getWidth() > $params['width'] || $imagem->getHeight() > $params['height']) { wiImage::load($file_dest)->resize($params['width'], $params['height'], $params['fit'], $params['scale'])->saveToFile($file_dest, null, 90); } // Cria imagem 800x600 //$file_800 = $path_dest.DS.$coluna.'800x600.'.$file_ext; //ecompHelper::redimensionaImg($file_dest, $file_800, 800, 600, $params['fit'], $params['scale'], 90); // Cria imagem 640x480 //$file_640 = $path_dest.DS.$coluna.'640x480.'.$file_ext; //ecompHelper::redimensionaImg($file_dest, $file_640, 640, 480, $params['fit'], $params['scale'], 90); // Cria imagem 320x240 //$file_320 = $path_dest.DS.$coluna.'320x240.'.$file_ext; //ecompHelper::redimensionaImg($file_dest, $file_320, 320, 240, $params['fit'], $params['scale'], 90); } } // altera o nome da imagem $cadastro->{$coluna} = $file_name; } } } //upload if ($campo->idtipo == 4 && $uploads['error'][$idcampo][$coluna] != 4) { $path_dest = ECOMP_PATH_UPLOADS . DS . $idcomponente . DS . $cadastro->id; $file = $uploads; $file_ext = strtolower(JFile::getExt($file['name'][$idcampo][$coluna])); $file_name = $coluna . '.' . $file_ext; $file_tmp = $file['tmp_name'][$idcampo][$coluna]; $file_dest = $path_dest . DS . $file_name; // apaga o arquivo @unlink($path_dest . DS . $cadastro->{$coluna}); if (JFile::upload($file_tmp, $file_dest)) { // altera o nome da imagem $cadastro->{$coluna} = $file_name; } } // salva os dados $cadastro->update(); } return true; }
function testPreserveTransparency() { $img = wiImage::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); }
include "../db.php"; if (isset($_POST["PHPSESSID"])) { session_id($_POST["PHPSESSID"]); } @session_start(); if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) { echo "There was a problem with the upload"; } if (move_uploaded_file($_FILES["Filedata"]["tmp_name"], "arquivos/" . $_FILES["Filedata"]["name"])) { $nome_arq = $_FILES["Filedata"]["name"]; $id_album = $_GET['id_album']; $aux = explode(".", $nome_arq); // Chama o arquivo com a classe WideImage require "wideimage/WideImage.inc.php"; // Carrega a imagem a ser manipulada $image = wiImage::load("arquivos/{$nome_arq}"); // Redimensiona a imagem (grande) $image = $image->resize(640, 480); // Salva a imagem em um arquivo $image->saveToFile("arquivos/{$aux['0']}" . "_g.jpg"); // Redimensiona a imagem (miniatura) $image = $image->resize(150, 100); // Salva a imagem em um arquivo $image->saveToFile("arquivos/{$aux['0']}" . "_p.jpg"); //unlink("/home/marcusev/public_html/admin/upload/arquivos/$aux[0]".".jpg"); $sql = "INSERT INTO imagem (id_album,nome_arquivo) VALUES ({$id_album},'{$aux['0']}_g.jpg')"; mysql_query($sql); } //exit(0); ?>
<?php /** This file is part of WideImage. WideImage is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. WideImage is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with WideImage; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA **/ require_once dirname(__FILE__) . '/helpers/common.inc.php'; //Registry::set('debug', 'text'); $img = wiImage::load(WI_IMG_PATH . Request::get('img')); $mask = wiImage::load(WI_IMG_PATH . 'mask-' . Request::get('mask') . '.gif'); $left = Request::getInt('left'); $top = Request::getInt('top'); $result = $img->applyMask($mask, $left, $top); $format = 'png'; img_header($format); echo $result->asString($format);
/** * Resize a Picture to some given dimensions (using the wideImage library) * * @param string $src_path Picture's source * @param string $dst_path Picture's destination * @param integer $param_width Maximum picture's width * @param integer $param_height Maximum picture's height * @param boolean $keep_original Do we have to keep the original picture ? * @param string $fit Resize mode (see the wideImage library for more information) */ function nw_resizePicture($src_path , $dst_path, $param_width , $param_height, $keep_original = false, $fit = 'inside') { require_once NW_MODULE_PATH . '/class/wideimage/WideImage.inc.php'; $resize = true; $pictureDimensions = getimagesize($src_path); if (is_array($pictureDimensions)) { $pictureWidth = $pictureDimensions[0]; $pictureHeight = $pictureDimensions[1]; if ($pictureWidth < $param_width && $pictureHeight < $param_height) { $resize = false; } } $img = wiImage::load($src_path); if ($resize) { $result = $img->resize($param_width, $param_height, $fit); $result->saveToFile($dst_path); } else { @copy($src_path, $dst_path); } if(!$keep_original) { @unlink( $src_path ) ; } return true; }
function testCreate() { // wiTrueColorImage, wiPaletteImage, wiImage and wiException are enough for autoload $img = wiImage::load(dirname(__FILE__) . '/images/fgnl.jpg'); }
<?php /** This file is part of WideImage. WideImage is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. WideImage is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with WideImage; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA **/ require_once dirname(__FILE__) . '/helpers/common.inc.php'; //Registry::set('debug', 'text'); $img = wiImage::load(WI_IMG_PATH . Request::get('img')); $result = $img->mirror(); $format = substr(Request::get('img'), -3); img_header($format); echo $result->asString($format);
function cria_imagem($imagem, $largura = null, $altura = null, $fit = 'inside', $scale = 'any', $wm = false) { // limpa o caminho, absoluto ou relativo $imagem = str_replace(JURI::base(), '', $imagem); $imagem = str_replace(JURI::base(1), '', $imagem); $imagem = str_replace('/', DS, JPATH_BASE . DS . $imagem); $imagem = str_replace(DS . DS, DS, $imagem); // se a imagem não existir if (!JFile::exists($imagem)) { // retorna o mesmo camiho com a variavel noexists=1 adicionada return $imagem . '?eload=noexists'; } // abre a clase Imagem require_once 'wideimage' . DS . 'lib' . DS . 'WideImage.inc.php'; $largura_real = wiImage::load($imagem)->getWidth(); $altura_real = wiImage::load($imagem)->getHeight(); // se a largura e a altura forem null if (is_null($largura) && is_null($altura)) { // pega a largura e altura da imagem original $largura = $largura_real; $altura = $altura_real; } // se a largura for maior que a largura original if ($largura > $largura_real) { $largura = $largura_real; } // se a altura for maior que a altura original if ($altura > $altura_real) { $altura = $altura_real; } // remover a extenção $imagemName = JFile::stripExt($imagem); // remove as barras do nome $imagemName = str_replace('/', '-', $imagemName); // Pasta para a imagem com base nos 10 primeiros caracteres do seu sha1 $imagemDir = 'cache/eload/' . substr(sha1_file($imagem), 0, 10); // se a pasta não existir if (!is_dir(JPATH_BASE . DS . $imagemDir)) { // tenta criar a mesma mkdir(JPATH_BASE . DS . $imagemDir); } $wminfo = ""; // caminho para o txt com informações da imagem com marca(s) d'água $wmsha1 = ""; // sha1 das imagens de marca d'água $wmpsha1 = ""; // sha1 dos parametros if (is_array($wm) && count($wm)) { $wminfo = JPATH_BASE . DS . $imagemDir . '/' . substr(sha1("{$imagem}_{$largura}x{$altura}_{$fit}_{$scale}"), 0, 8) . ".txt"; foreach ($wm as $marca) { $wmsha1 .= substr(sha1_file($marca[0]), 0, 4); $wmpsha1 .= substr(sha1($marca[6]), 0, 4); } } $novaImagem = "{$imagem}_{$largura}x{$altura}_{$fit}_{$scale}{$wmsha1}"; // sha1 do nome do arquivo $novaImagem = substr(sha1($novaImagem), 0, 8); // adiciona a ext no arquivo $novaImagem = $novaImagem . '.' . JFile::getExt($imagem); // cria a string com o endereço da nova imagem $cache = "{$imagemDir}/{$novaImagem}"; if (!empty($wminfo)) { if (!file_exists($wminfo)) { file_put_contents($wminfo, "{$novaImagem}|{$wmpsha1}"); } else { $wmold = file_get_contents($wminfo); $wmoldinfo = explode('|', $wmold); if ($novaImagem != $wmoldinfo[0] || $wmpsha1 != $wmoldinfo[1]) { if (file_exists(JPATH_BASE . DS . $imagemDir . '/' . $wmoldinfo[0])) { unlink(JPATH_BASE . DS . $imagemDir . '/' . $wmoldinfo[0]); } file_put_contents($wminfo, "{$novaImagem}|{$wmpsha1}"); } } } // se a imagem não existir if (!file_exists(JPATH_BASE . DS . $cache)) { $novaimagem = wiImage::load($imagem)->resize($largura, $altura, $fit, $scale); if (is_array($wm) && count($wm)) { foreach ($wm as $marca) { $menor = $largura < $altura ? $largura : $altura; $imgmarca = wiImage::load($marca[0])->resize($marca[2], $marca[3], 'inside', 'down'); switch ($marca[1]) { case 'tl': $v = $marca[4]; $h = $marca[5]; break; case 'tc': $v = $marca[4]; $h = ($novaimagem->getWidth() - $imgmarca->getWidth()) / 2; break; case 'tr': $v = $marca[4]; $h = $novaimagem->getWidth() - $imgmarca->getWidth() - $marca[5]; break; case 'bl': $v = $novaimagem->getHeight() - $imgmarca->getHeight() - $marca[4]; $h = $marca[5]; break; case 'bc': $v = $novaimagem->getHeight() - $imgmarca->getHeight() - $marca[4]; $h = ($novaimagem->getWidth() - $imgmarca->getWidth()) / 2; break; case 'br': $v = $novaimagem->getHeight() - $imgmarca->getHeight() - $marca[4]; $h = $novaimagem->getWidth() - $imgmarca->getWidth() - $marca[5]; break; case 'cc': $v = ($novaimagem->getHeight() - $imgmarca->getHeight()) / 2; $h = ($novaimagem->getWidth() - $imgmarca->getWidth()) / 2; break; } $novaimagem = $novaimagem->merge($imgmarca, $h, $v); } } $novaimagem->saveToFile(JPATH_BASE . DS . $cache, null, 90); } $cache = JURI::base() . $cache; return $cache; }
/** * Resize a Picture to some given dimensions (using the wideImage library) * * @param string $src_path Picture's source * @param string $dst_path Picture's destination * @param integer $param_width Maximum picture's width * @param integer $param_height Maximum picture's height * @param boolean $keep_original Do we have to keep the original picture ? * @param string $fit Resize mode (see the wideImage library for more information) */ function resizePicture($src_path, $dst_path, $param_width, $param_height, $keep_original = false, $fit = 'inside') { require_once MYSHOP_PATH . 'class/wideimage/WideImage.inc.php'; $img = wiImage::load($src_path); $result = $img->resize($param_width, $param_height, $fit); $result->saveToFile($dst_path); if (!$keep_original) { @unlink($src_path); } }
public function loadImage($imagePath) { return wiImage::load($imagePath); }
</form> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { include "../db.php"; $files = $_FILES['files']; $directory = 'arquivos/'; $id_album = $_GET['id_album']; for ($i = 0, $c = count($files); $i <= $c; ++$i) { $upload = move_uploaded_file($files['tmp_name'][$i], $directory . $files['name'][$i]); $aux = explode(".", $files['name'][$i]); // Chama o arquivo com a classe WideImage require "wideimage/WideImage.inc.php"; // Carrega a imagem a ser manipulada $image = wiImage::load("arquivos/{$aux['0']}" . ".jpg"); // Redimensiona a imagem (grande) $image = $image->resize(640, 480); // Salva a imagem em um arquivo $image->saveToFile("arquivos/{$aux['0']}" . "_g.jpg"); // Redimensiona a imagem (miniatura) $image = $image->resize(150, 100); // Salva a imagem em um arquivo $image->saveToFile("arquivos/{$aux['0']}" . "_p.jpg"); unlink("arquivos/{$aux['0']}" . ".jpg"); $sql = "INSERT INTO imagem (id_album,nome_arquivo) VALUES ({$id_album},'" . $aux[0] . "_g." . $aux[1] . "')"; mysql_query($sql); echo "<script>\n\t\t\t\t\t\talert('Upload realizado com sucesso!'); \n\t\t\t\t\t\twindow.parent.location.href='http://www.marcusevinicius.com.br/admin/adm_principal.php?area=fotos&id_album={$id_album}'; \n\t\t\t\t\t\twindow.parent.Shadowbox.close();\n\t\t\t\t</script>"; } } ?>
function testCanvasInstance() { $img = wiImage::load(IMG_PATH . 'fgnl.jpg'); $canvas1 = $img->getCanvas(); $this->assertTrue($canvas1 instanceof wiCanvas); $canvas2 = $img->getCanvas(); $this->assertTrue($canvas1 === $canvas2); }