public function atualizarfotoAction() { General::permissaoAuth(false); $nu_imagem = uniqid(); if ($_FILES['Filedata']) { $tmpPath = APPLICATION_PATH . "/../data/tmp/"; $finfo = pathinfo($_FILES['Filedata']['name']); $name = $nu_imagem . '.' . $finfo['extension']; if (!in_array(strtolower($finfo['extension']), array('jpg', 'png', 'jpeg'))) { echo json_encode(array('status' => 0, 'msg' => _("Extensão não permitida!"))); die; } @move_uploaded_file($_FILES['Filedata']['tmp_name'], $tmpPath . $name); try { copy($tmpPath . $name, $tmpPath . "128_" . $name); $canvas = canvas::Instance($tmpPath . "128_" . $name); $canvas->redimensiona(128, 128, 'crop'); $canvas->grava($tmpPath . "128_" . $name, 90); copy($tmpPath . $name, $tmpPath . "70_" . $name); $canvas = canvas::Instance(); $canvas->carrega($tmpPath . "70_" . $name); $canvas->redimensiona(70, 70, 'crop'); $canvas->grava($tmpPath . "70_" . $name, 90); copy($tmpPath . $name, $tmpPath . "50_" . $name); $canvas = canvas::Instance(); $canvas->carrega($tmpPath . "50_" . $name); $canvas->redimensiona(50, 50, 'crop'); $canvas->grava($tmpPath . "50_" . $name, 90); copy($tmpPath . $name, $tmpPath . "32_" . $name); $canvas = canvas::Instance(); $canvas->carrega($tmpPath . "32_" . $name); $canvas->redimensiona(32, 32, 'crop'); $canvas->grava($tmpPath . "32_" . $name, 90); @unlink($tmpPath . $name); } catch (Exception $e) { echo json_encode(array('status' => 0, 'msg' => 'Error!')); @unlink($tmpPath . "32_" . $name); @unlink($tmpPath . "50_" . $name); @unlink($tmpPath . "70_" . $name); @unlink($tmpPath . "128_" . $name); } try { Model_Usuario::getInstance()->cadastrarFoto(array('nu_imagem' => $nu_imagem)); $s3 = new S3(Zend_Registry::get('application')->sys->aws_accesskey, Zend_Registry::get('application')->sys->aws_secretkey); $bucket = Zend_Registry::get('application')->sys->aws_s3_bucket; $s3->putObjectFile($tmpPath . "32_" . $name, $bucket, "32_" . $name, S3::ACL_PUBLIC_READ); $s3->putObjectFile($tmpPath . "50_" . $name, $bucket, "50_" . $name, S3::ACL_PUBLIC_READ); $s3->putObjectFile($tmpPath . "70_" . $name, $bucket, "70_" . $name, S3::ACL_PUBLIC_READ); $s3->putObjectFile($tmpPath . "128_" . $name, $bucket, "128_" . $name, S3::ACL_PUBLIC_READ); @unlink($tmpPath . "32_" . $name); @unlink($tmpPath . "50_" . $name); @unlink($tmpPath . "70_" . $name); @unlink($tmpPath . "128_" . $name); } catch (Exception $e) { echo json_encode(array('status' => 0, 'msg' => _("Erro ao processar as imagens"))); @unlink($tmpPath . "32_" . $name); @unlink($tmpPath . "50_" . $name); @unlink($tmpPath . "70_" . $name); @unlink($tmpPath . "128_" . $name); } $_SESSION['tw_auth']['nu_imagem'] = $nu_imagem; $url_imagem = General::urlImgUser(array('nu_imagem' => $nu_imagem, 'size' => 50)); echo json_encode(array('status' => 1, 'msg' => 'success', 'nu_imagem' => $nu_imagem, 'url_imagem' => $url_imagem)); } }
/** * Método singleton para que apenas uma instancia da classe seja utilizada no servidor. * @param String $origem * @return canvas */ public static function Instance($origem = '') { if (empty(self::$instance)) { self::$instance = new canvas($origem); } else { self::$instance->resetar(); } return self::$instance; }
function test_set_invalid_color() { $img = new canvas(); $this->assertFalse($img->set_rgb("invalid_color")); }
<?php error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE); ini_set('display_errors', 'On'); ini_set('display_startup_errors', true); require_once "../canvas.php"; $file = "test_image.jpg"; $canvas = new canvas($file); $canvas->set_rgb('#df0d32')->merge("test_image.png", array("right", "bottom"))->filter("blur", 23)->show();
function test_save_invalid_image() { $img = new canvas(dirname(__FILE__) . "/../README.markdown"); $this->assertFalse($img->save("/tmp/README.markdown")); }
<?php $error = null; try { if (isset($_FILES['Image'])) { $ext = strtolower(pathinfo($_FILES['Image']['name'], PATHINFO_EXTENSION)); if (!in_array($ext, array('png', 'jpg', 'bmp', 'jpeg', 'gif'))) { throw new Exception('Formato de imagem inválido'); } require_once "./canvas.php"; $canvas = new canvas(); $canvas->carrega($_FILES['Image']['tmp_name']); $canvas->redimensiona(400, 400, 'crop'); $canvas->marca('minas.png', 'topo', 'esquerda'); $canvas->grava(); exit; } } catch (Exception $e) { $error = $e->getMessage(); } ?> <!DOCTYPE html> <html lang="pt-br"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <title>Mariana - Minas Gerais</title>
function test_image_resize_with_percentual_width_and_height() { $img = new canvas(); $img->create_empty_image(200, 200); $img->resize("25%", "30%"); $img->save("/tmp/test_image.jpg"); $imagesize = getimagesize("/tmp/test_image.jpg"); $this->assertEqual($imagesize[0], 50); $this->assertEqual($imagesize[1], 60); @unlink("/tmp/test_image.jpg"); }
<?php include '../canvas.php'; $img = new canvas(); $img->create_empty_image(200, 200, $_GET["format"]); $img->show();
function test_create_empty_image_with_alpha() { $img = new canvas(); $this->assertTrue($img->create_empty_image(200, 300, "png", 127) instanceof canvas); }
public function test_bucket_fill() { $c = new canvas(4, 4); //use the tool bucket-fill to fill all area arround the given point with the char passed as arg. $this->assertTrue($c->bucket_fill(array(1, 1), 'c')); }
move_uploaded_file($fileTmp, $pasta . $fileName); // Verifica se a imagem é menor que o limite máximo, mantem a largura original. $realWidth = getImageDimens($pasta . $fileName, "largura"); if ($realWidth < $maxWidth) { $imageWidth = $realWidth; } else { $imageWidth = $maxWidth; } // Manipula a foto principal $img = new canvas(); $img->carrega($pasta . $fileName); $img->redimensiona($imageWidth, 0, $tipoCorte); $img->grava($pasta . $fileName, $qualidade); // Se solicitado, envia thumb manipulada if ($thumbs == "Sim") { $oThumb = new canvas(); $oThumb->carrega($pasta . $fileName); $oThumb->redimensiona($thumbW, $thumbH, $thumbCorte); $oThumb->grava($pasta . "thumb-" . $fileName, $qualidade); } insert(array("cond", "foto"), array($cond, $fileName), "site_static_fotos"); } ?> <script> sweetRedir("Sucesso", "Fotos enviadas com sucesso.", "success", "<?php echo CP; ?> /view/static/<?php echo $cond; ?>
<?php /*error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE); ini_set('display_errors', 1); ini_set('display_startup_errors', true);*/ include "../../../inc/config.inc.php"; include "../../../lib/canvas/canvas.php"; include "inc/autoload.inc.php"; include "../../sistema/home/inc/doc.inc.php"; if (isset($_GET["MDP_ID"])) { //consulta o objeto, se ja estiver preenchido a variavel nã atualiza mais.. $arrConsulta["MDP_ID"] = $_GET["MDP_ID"]; $arrObjRegistroEmail = NegMalaDiretaPessoa::getInstance()->consultar($arrConsulta); $arrObjRegistroEmail = $arrObjRegistroEmail["objects"]; $objMalaPessoa = new MalaDiretaPessoa(); $objMalaPessoa = $arrObjRegistroEmail[0]; if ($objMalaPessoa->getDataVisualizacao() == null) { $_GET["MDP_DataHoraLeitura"] = date("d/m/Y H:i:s"); $arrObjMalaPessoa = NegMalaDiretaPessoa::getInstance()->registrarVisualizacaoEmail($_GET); } } $can = new canvas(); $can->create_empty_image(1, 1); $can->show();