Example #1
0
 function uploadAvatar($input_name, $max_file_size)
 {
     $overwrite = 1;
     $dir = 'upload/avatars/';
     $file_types = array(1 => 'jpg', 'jpeg', 'gif', 'png', 'JPG', 'JPEG', 'GIF', 'PNG');
     $file_mimes = array(1 => 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png');
     $file_name = $_SESSION['login'] . '_user';
     if (isset($_POST['send_avatar'])) {
         if (!$_FILES[$input_name]['name']) {
             $this->msg('Nie wybrano pliku do załadowania!', 1);
         } else {
             if (filesize($_FILES[$input_name]['tmp_name']) <= $max_file_size * 1024) {
                 $file_ex = pathinfo($_FILES[$input_name]['name']);
                 $image_info = @getimagesize($_FILES[$input_name]['tmp_name']);
                 if (array_search($file_ex['extension'], $file_types) && array_search($image_info['mime'], $file_mimes)) {
                     if ($overwrite == 0 && file_exists($dir . $file_name . "." . $file_ex['extension'])) {
                         $this->msg('Taki plik już istnieje.', 1);
                     }
                     if (!move_uploaded_file($_FILES[$input_name]['tmp_name'], $dir . $file_name . "." . $file_ex['extension'])) {
                         $this->msg('Wgrywanie pliku nie powiodło się.', 1);
                     } else {
                         $upload_dir = $dir . $file_name . "." . $file_ex['extension'];
                         mysql_query("UPDATE `{$this->table}` SET `avatar`='{$upload_dir}' WHERE `user`='" . $_SESSION['login'] . "'");
                         //Zmina rozmiaru avatara
                         list($width, $height, $type, $attr) = getimagesize($upload_dir);
                         if ($width > 120 || $height > 120) {
                             require_once 'admin/lib/imageworkshop.lib.php';
                             $createFolders = false;
                             $backgroundColor = null;
                             $imageQuality = 95;
                             $imageLayer = new ImageWorkshop(array("imageFromPath" => $upload_dir));
                             $imageLayer->resizeInPixel(120, 120, true);
                             $imageLayer->save($dir, $file_name . "." . $file_ex['extension'], $createFolders, $backgroundColor, $imageQuality);
                         }
                         $this->msg('Avatar został pomyślnie załadowany.', 3);
                     }
                 } else {
                     $this->msg('Niedozwolone rozszerzenie lub typ pliku!', 1);
                 }
             } else {
                 $this->msg('Wybrany plik jest za wielki! Dozwolony rozmiar to ' . $max_file_size . ' kB.', 1);
             }
         }
     }
 }
Example #2
0
 public function __construct($filepath)
 {
     $this->filepath = $filepath;
     require_once __DIR__ . '/lib/GifCreator.php';
     require_once __DIR__ . '/lib/GifFrameExtractor.php';
     if (GifFrameExtractor::isAnimatedGif($this->filepath)) {
         $gfe = new GifFrameExtractor();
         $frames = $gfe->extract();
         $newFrames = [];
         foreach ($frames as $f) {
             require_once __DIR__ . '/lib/PHPImageWorkshop/ImageWorkshop.php';
             $layer = ImageWorkshop::initFromResourceVar($f['image']);
             //We use resizeScaleWidth in imagestatus
             //$layer->resizeInPixel($thumbWidth, $thumbHeight, $conserveProportion, $positionX, $positionY, $position);
             //$layer->resizeByNarrowSideInPixel($newNarrowSideWidth, $conserveProportion);
         }
     }
 }
Example #3
0
 function watermark($file, $watermark, $dir)
 {
     require_once 'admin/lib/imageworkshop.lib.php';
     $info = pathinfo($file);
     if ($info['extension'] != 'gif') {
         $imageLayer = new ImageWorkshop(array("imageFromPath" => $file));
         $watermarkLayer = new ImageWorkshop(array("imageFromPath" => $watermark));
         $imageLayer->addLayer(1, $watermarkLayer, 5, 5, "RB");
         $createFolders = false;
         $backgroundColor = null;
         $imageQuality = 100;
         $imageLayer->save($dir, $info['filename'] . '.' . $info['extension'], $createFolders, $backgroundColor, $imageQuality);
     }
 }
 /**
  * Called to initialize a text layer
  * (Update layer width and height)
  *
  * @param string $text
  * @param string $fontPath
  * @param integer $fontSize
  * @param string $fontColor
  * @param integer $textRotation
  * @param integer $backgroundColor
  */
 public function initializeTextImage($text, $fontPath, $fontSize = 13, $fontColor = "ffffff", $textRotation = 0, $backgroundColor = null)
 {
     unset($this->image);
     $textDimensions = ImageWorkshop::getTextBoxDimension($fontSize, $textRotation, $fontPath, $text);
     $this->width = $textDimensions["width"];
     $this->height = $textDimensions["height"];
     if ($backgroundColor) {
         $this->image = static::generateImage($this->width, $this->height, $backgroundColor, 0);
     } else {
         $this->image = static::generateImage($this->width, $this->height);
     }
     $this->write($text, $fontPath, $fontSize, $fontColor, $textDimensions["left"], $textDimensions["top"], $textRotation);
 }
Example #5
0
<?php

require_once PHPImageWorkshop / ImageWorkshop . php;
$norwayLayer = ImageWorkshop::initFromPath('/var/www/html/samples/php/watermark/case6/logo/csi.jpg');
// This is the text layer
$textLayer = ImageWorkshop::initTextLayer('© PHP Image Workshop', '/var/www/html/samples/php/watermark/case6/arial.ttf', 11, 'ffffff', 0);
// We add the text layer 12px from the Left and 12px from the Bottom ("LB") of the norway layer:
$norwayLayer->addLayerOnTop($textLayer, 12, 12, "LB");
$image = $norwayLayer->getResult();
header('Content-type: image/jpeg');
imagejpeg($image, null, 95);
// We chose to show a JPG with a quality of 95%
exit;