Example #1
0
 /**
  * Render the given element
  *
  * @return array
  */
 public function renderInternal()
 {
     $image = new Image();
     if (!($this->contentObject->data['imageorient'] & 24)) {
         $lines = $image->render($this->contentObject, $this->configuration);
         $lines[] = '';
     }
     $lines[] = $this->breakContent(strip_tags($this->parseBody($this->contentObject->data['bodytext'])));
     if ($this->contentObject->data['imageorient'] & 24) {
         $lines[] = '';
         $lines = array_merge($lines, $image->render($this->contentObject, $this->configuration));
     }
     return $lines;
 }
Example #2
0
 /**
  * Renders image
  *
  * @param int $quality
  * @throws Imagify_Exception
  * @return string
  */
 public function render($quality = 80)
 {
     if (!isset($this->_image)) {
         throw new Imagify_Exception('Image is not yet created to render it');
     }
     echo $this->_image->render(null, $quality);
 }
 public function makeThumbnail($id, $field, $w, $h, $crop = false, $enlarge = false)
 {
     $path = $this->getImagePath($id, $field);
     //		\helpers\Debug::prePrintR($path);
     if (!empty($path)) {
         $tn = ($crop ? 'cr' : '') . ($enlarge ? 'en' : '');
         $cache = str_replace($this->tableMeta->get('table'), $this->tableMeta->get('table') . '/tmp/' . $tn . $w, $path);
         if (file_exists($cache)) {
             $ext = pathinfo($path, PATHINFO_EXTENSION);
             $img = new \Image($cache);
             echo $img->render($ext);
             return true;
         } elseif (file_exists($path)) {
             // Создаём и сохраняем миниатюру
             $img = new \Image($path);
             $img->resize($w, $h, $crop, $enlarge);
             $dir = $this->makeDirStructure($id, $tn . $w);
             if ($dir) {
                 $ext = pathinfo($path, PATHINFO_EXTENSION);
                 $f3 = \Base::instance();
                 $res = $f3->write($dir . $tn . $field . '.' . $ext, $img->dump());
                 echo $img->render($ext);
                 return true;
             }
         }
     }
     return false;
 }
Example #4
0
 public static function captchaF3()
 {
     $img = new \Image();
     $img->captcha('template/captchaFonts/Browning.ttf', 16, 5, 'SESSION.captcha');
     $_SESSION['captcha'] = password_hash($_SESSION['captcha'], PASSWORD_DEFAULT);
     ob_start();
     $img->render();
     $image_data = ob_get_contents();
     ob_end_clean();
     echo base64_encode($image_data);
 }
 public function photo_handler($f3)
 {
     /*echo $f3->get('PARAMS.certi_type') . "<br>";
     		
     		echo $f3->get('PARAMS.category') . "<br>";
     		
     		echo $f3->get('PARAMS.filename') . "<br>";*/
     $temp = $f3->get('certi_folder');
     //echo $temp[$f3->get('PARAMS.certi_type')];
     $docpath = DOCROOT . "/";
     $docpath .= $f3->get("doc_folder_name") . "/";
     $docpath .= $temp[$f3->get('PARAMS.certi_type')] . "/";
     $docpath .= $f3->get('PARAMS.category') . "/";
     $file = $f3->get('PARAMS.filename');
     $file = setEncryptDecrption($file, false);
     $img = new Image($file, FALSE, $docpath);
     $img->render();
     exit;
 }
Example #6
0
 function thumbnail($file, $width, $height, $crop = true, $enlarge = true)
 {
     $domain = $this->f3->get("domain");
     //test_array($file);
     $thumb = explode(".", $file);
     $thumbExt = $thumb[count($thumb) - 1];
     $thumb = str_replace("." . $thumbExt, "_thumb." . $thumbExt, $file);
     $cfg = $this->f3->get("cfg");
     $folder = $cfg['media'];
     $path = $folder;
     $path = $this->f3->fixslashes($path);
     $path = str_replace("//", "/", $path);
     //test_array($file);
     $folder = "";
     //	test_array($file);
     header('Pragma: public');
     header('Cache-Control: max-age=86400');
     header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 86400));
     $thumb = new Image($file, false, $path);
     $thumb->resize($width, $height, $crop, $enlarge);
     $thumb->render('jpeg');
     $showthumb = true;
 }
Example #7
0
            if ($crop) {
                $image->scaleSpace($width, $height, $_REQUEST['bg']);
            } else {
                $image->scale($width, $height, $_REQUEST['bg']);
            }
            $image->renderOutputHeader($actual_name);
            $image->render($cacheFile);
            print file_get_contents($cacheFile);
        } else {
            if (!($image = new Image($cacheFile, $quality))) {
                die("<h1>Symphony Fatal Error</h1><p>Error opening cached image<hr /><em>" . $_SERVER['SERVER_SIGNATURE'] . "</em>");
            }
            $image->renderOutputHeader($actual_name);
            $image->render();
        }
    } else {
        if (!($image = new Image($file, $quality))) {
            die("<h1>Symphony Fatal Error</h1><p>Error creating Image in memory<hr /><em>" . $_SERVER['SERVER_SIGNATURE'] . "</em>");
        }
        if ($crop) {
            $image->scaleSpace($width, $height, $_REQUEST['bg']);
        } else {
            $image->scale($width, $height, $_REQUEST['bg']);
        }
        $image->renderOutputHeader($actual_name);
        $image->render();
    }
    $image->close();
    unset($image);
    exit;
}
function file_attach($id)
{
    $con = connection();
    $date = date("Y-m-d H:i:s");
    $max_file_size = 4194304;
    if (!$_FILES['userfile']['name'][0] == '') {
        if (isset($_FILES['userfile']['tmp_name'])) {
            for ($i = 0; $i < count($_FILES['userfile']['tmp_name']); $i++) {
                //$allowed_filetypes = array('.pdf','.txt','.word','.doc','.xls','.docx','.ppt','.xlsx');
                $allowed_filetypes = array('.png', '.jpeg', '.jpg');
                $final_path = "../attachment/";
                $final_path_thumb = "../attachment/thumb";
                $filename = $_FILES['userfile']['name'][$i];
                $ext = substr($filename, strpos($filename, '.'), strlen($filename) - 1);
                if (!in_array($ext, $allowed_filetypes)) {
                    die('The file that you are trying to upload is not allowed.');
                }
                if (!is_uploaded_file($_FILES['userfile']['tmp_name'][$i])) {
                    $message = 'No file uploaded';
                }
                if ($_FILES['userfile']['size'][$i] > $max_file_size) {
                    $message = "File size exceeds {$max_file_size} limit";
                }
                $new_filename = md5(date("Y-m-d H:i:s")) . rand() . $ext;
                $p = $final_path . $new_filename;
                //echo $_FILES['userfile']['tmp_name'][$i];
                //echo "<br>";
                if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $p)) {
                    require_once 'image.class.php';
                    $image = new Image($p);
                    $image->destination = $final_path_thumb . '/' . $new_filename;
                    //echo $final_path_thumb.'/'.$new_filename;
                    $image->constraint = 'w';
                    $image->size = 220;
                    $image->quality = 100;
                    $image->render();
                    if (store_file($id, $new_filename)) {
                        return true;
                    } else {
                        return false;
                    }
                    //
                } else {
                    return false;
                }
            }
        }
    }
}
Example #9
0
File: gd.php Project: homm/image
 protected function _do_watermark(Image $watermark, $offset_x, $offset_y, $opacity)
 {
     if (!Image_GD::$_bundled) {
         throw new Kohana_Exception('This method requires :function, which is only available in the bundled version of GD', array(':function' => 'imagelayereffect'));
     }
     // Loads image if not yet loaded
     $this->_load_image();
     // Create the watermark image resource
     $overlay = imagecreatefromstring($watermark->render());
     // Get the width and height of the watermark
     $width = imagesx($overlay);
     $height = imagesy($overlay);
     if ($opacity < 100) {
         // Convert an opacity range of 0-100 to 127-0
         $opacity = round(abs($opacity * 127 / 100 - 127));
         // Allocate transparent white
         $color = imagecolorallocatealpha($overlay, 255, 255, 255, $opacity);
         // The transparent image will overlay the watermark
         imagelayereffect($overlay, IMG_EFFECT_OVERLAY);
         // Fill the background with transparent white
         imagefilledrectangle($overlay, 0, 0, $width, $height, $color);
     }
     // Alpha blending must be enabled on the background!
     imagealphablending($this->_image, TRUE);
     if (imagecopy($this->_image, $overlay, $offset_x, $offset_y, 0, 0, $width, $height)) {
         // Destroy the overlay image
         imagedestroy($overlay);
     }
 }
Example #10
0
 protected function _do_watermark(Image $watermark, $offset_x, $offset_y, $opacity)
 {
     // Create the watermark image resource
     $overlay = imagecreatefromstring($watermark->render());
     // Get the width and height of the watermark
     $width = imagesx($overlay);
     $height = imagesy($overlay);
     if ($opacity < 100) {
         // Convert an opacity range of 0-100 to 127-0
         $opacity = round(abs($opacity * 127 / 100 - 127));
         // Allocate transparent white
         $color = imagecolorallocatealpha($overlay, 255, 255, 255, $opacity);
         // The transparent image will overlay the watermark
         imagelayereffect($overlay, IMG_EFFECT_OVERLAY);
         // Fill the background with transparent white
         imagefilledrectangle($overlay, 0, 0, $width, $height, $color);
     }
     // Alpha blending must be enabled on the background!
     imagealphablending($this->_image, TRUE);
     if (imagecopy($this->_image, $overlay, $offset_x, $offset_y, 0, 0, $width, $height)) {
         // Destroy the overlay image
         imagedestroy($overlay);
     }
 }
Example #11
0
 public function actionImage()
 {
     $file_name = Yii::app()->request->getParam('path');
     $tmp_path = Yii::app()->runtimePath;
     $new_filename = $tmp_path . '/' . $file_name;
     Yii::import('application.extensions.image.Image');
     $image_base = new Image($new_filename);
     $image_base->render();
 }
 protected function _do_watermark(Image $image, $offset_x, $offset_y, $opacity)
 {
     $filein = isset($this->filetmp) ? $this->filetmp : $this->file;
     // Create temporary file to store the watermark image
     $watermark = tempnam(Upload::$default_directory, '');
     $fp = fopen($watermark, 'wb');
     if (!fwrite($fp, $image->render())) {
         return FALSE;
     }
     // Merge watermark with image
     $fileout = tempnam(Upload::$default_directory, '');
     $command = Image_ImageMagick::get_command('composite');
     $command .= ' -quality 100 -dissolve ' . escapeshellarg($opacity) . '% -geometry +' . escapeshellarg($offset_x) . '+' . escapeshellarg($offset_y);
     $command .= ' ' . escapeshellarg($watermark) . ' ' . escapeshellarg($filein);
     $command .= ' ' . escapeshellarg('PNG:' . $fileout);
     //save as PNG to keep transparency
     exec($command, $response, $status);
     if ($status) {
         return FALSE;
     }
     // Delete temp files and close handlers
     fclose($fp);
     unlink($watermark);
     // Delete old tmp file if exist
     if (isset($this->filetmp) && file_exists($this->filetmp)) {
         unlink($this->filetmp);
     }
     // Update image data
     $this->filetmp = $fileout;
     return TRUE;
 }
Example #13
0
 function render($type = 'jpg', $dst_file = '')
 {
     return parent::render($type, $dst_file);
 }
Example #14
0
 /**
  * @param \Base $f3
  * @param array $params
  * @throws \Exception
  */
 public function avatar($f3, $params)
 {
     // Ensure proper content-type for JPEG images
     if ($params["format"] == "jpg") {
         $params["format"] = "jpeg";
     }
     $user = new \Model\User();
     $user->load($params["id"]);
     if ($user->avatar_filename && is_file("uploads/avatars/" . $user->avatar_filename)) {
         // Use local file
         $img = new \Image($user->avatar_filename, null, "uploads/avatars/");
         $img->resize($params["size"], $params["size"]);
         // Render and output image
         header("Content-type: image/" . $params["format"]);
         $img->render($params["format"]);
     } else {
         // Send user to Gravatar
         $f3->reroute($f3->get("SCHEME") . ":" . \Helper\View::instance()->gravatar($user->email, $params["size"]), true);
     }
 }
Example #15
0
 /**
  * Execute a watermarking.
  *
  * @param   Image    $image     watermarking Image
  * @param   integer  $offset_x  offset from the left
  * @param   integer  $offset_y  offset from the top
  * @param   integer  $opacity   opacity of watermark
  * @return  void
  */
 protected function _do_watermark(Image $watermark, $offset_x, $offset_y, $opacity)
 {
     if (empty(GD::$_available_functions[GD::IMAGELAYEREFFECT])) {
         die('This method requires "imagelayereffect", which is only available in the bundled version of GD');
     }
     // Loads image if not yet loaded
     $this->_load_image();
     // Create the watermark image resource
     $overlay = imagecreatefromstring($watermark->render());
     imagesavealpha($overlay, TRUE);
     // Get the width and height of the watermark
     $width = imagesx($overlay);
     $height = imagesy($overlay);
     if ($opacity < 100) {
         // Convert an opacity range of 0-100 to 127-0
         $opacity = round(abs($opacity * 127 / 100 - 127));
         // Allocate transparent gray
         $color = imagecolorallocatealpha($overlay, 127, 127, 127, $opacity);
         // The transparent image will overlay the watermark
         imagelayereffect($overlay, IMG_EFFECT_OVERLAY);
         // Fill the background with the transparent color
         imagefilledrectangle($overlay, 0, 0, $width, $height, $color);
     }
     // Alpha blending must be enabled on the background!
     imagealphablending($this->_image, TRUE);
     if (imagecopy($this->_image, $overlay, $offset_x, $offset_y, 0, 0, $width, $height)) {
         // Destroy the overlay image
         imagedestroy($overlay);
     }
 }
Example #16
0
<?php

// passes thru a image (with optional width & height specified)
namespace cd;

$name = File::getUploadPath($this->owner);
if (!empty($_GET['w']) && !empty($_GET['h'])) {
    $im = new ImageResizer($name);
    if ($_GET['w'] <= $im->getWidth() && $_GET['h'] <= $im->getHeight()) {
        $im->resizeAspect($_GET['w'], $_GET['h']);
    }
} else {
    $im = new Image($name);
}
$im->render();
Example #17
0
 /**
  * Demonstrates how to use the Image libarary..
  */
 function image()
 {
     // Application Upload directory
     $dir = realpath(DOCROOT . 'upload') . '/';
     // Image filename
     $image = DOCROOT . 'kohana.png';
     // Create an instance of Image, with file
     // The orginal image is not affected
     $image = new Image($image);
     // Most methods are chainable
     // Resize the image, crop the center left
     $image->resize(200, 100)->crop(150, 50, 'center', 'left');
     // Display image in browser
     $image->render();
     // Save the image
     $image->save($dir . 'mypic_thumb.jpg');
     //echo Kohana::debug($image);
 }
Example #18
0
 /**
  * show an image, called by image, thumb, sizer
  *
  * @param integer $w 
  * @param integer $h 
  * @param integer $image 
  * @return void
  * @author Andy Bennett
  */
 protected function show($w = null, $h = null, $image = false)
 {
     $row = $this->get_image_row($image);
     if (isset($row->preview_id) and $row->preview_id > 0) {
         $row = $row->preview;
     }
     // set up the image's path and error if the file doesn't exist
     $row->full_path = Kohana::config('upload.directory') . '/' . $row->file_name;
     if (!file_exists($row->full_path)) {
         Kohana::log('error', 'Invalid file path: ' . $row->full_path);
         throw new Kohana_404_Exception($row->orig_name, 'common/error_404');
     }
     // allow for flipping the image via the query string
     $flip = Input::instance()->get('flip');
     $flips = array('h' => 5, 'v' => 6);
     // get the master dimension from the query string, use 'a' if not set
     $dimension = Input::instance()->get('d', 'a');
     // possible master image dimensions
     $dimensions = array('n' => Image::NONE, 'a' => Image::AUTO, 'h' => Image::HEIGHT, 'w' => Image::WIDTH);
     // set the master dimension
     $d = isset($dimensions[$dimension]) ? $dimensions[$dimension] : $dimensions['a'];
     // ensure the file is an image and the width and height properties aren't null
     if ($row->is_image and !is_null($w) and !is_null($h)) {
         // create an image object
         $image = new Image($row->full_path);
         if (!is_null($flip) and isset($flips[$flip])) {
             $image->flip($flips[$flip]);
         }
         // get the current width and height
         $rw = $image->width;
         $rh = $image->height;
         // if width/height is not a number, use the current width/height
         $w = is_numeric($w) ? $w : $rw;
         $h = is_numeric($h) ? $h : $rh;
         // $image->quality(75);
         // resize the image, using the width, height and master dimension
         $image->resize($w, $h, $d);
         // if we are not using cache, render straight to the browser
         if (!$this->use_cache) {
             $image->render();
             die;
         }
         if ($this->border !== FALSE) {
             $this->add_border($image);
             $row->full_path = $this->cache_path;
         } else {
             // save the image to the cache, set the file path to the cache path
             $image->save($this->cache_path);
             $row->full_path = $this->cache_path;
         }
     }
     // render the file to the browser
     $this->render($row->full_path, null, $row->orig_name);
 }
Example #19
0
 /**
  * Render the drawing with correct headers.
  * 
  * @return mixed
  */
 public function render()
 {
     $this->Renderer->render();
 }
 /**
  * Demonstrates how to use the Image libarary..
  */
 function image()
 {
     // For testing only, save the new image in DOCROOT
     $dir = realpath(DOCROOT);
     // Original Image filename
     $image = DOCROOT . 'kohana.png';
     // Create an instance of Image, with file
     // The orginal image is not affected
     $image = new Image($image);
     // Most methods are chainable
     // Resize the image, crop the center left
     $image->resize(200, 100)->crop(150, 50, 'center', 'left');
     // Display image in browser.
     // Keep the actions, to be applied when saving the image.
     $image->render($keep_actions = TRUE);
     // Save the image, as a jpeg
     // Here the actions will be discarded, by default.
     $image->save($dir . '/mypic_thumb.jpg');
     //echo Kohana::debug($image);
 }
Example #21
0
} else {
    if ($section == "thumbnail") {
        require_once '../../vendor/bcosca/fatfree/lib/image.php';
        $file = isset($_GET['file']) ? $_GET['file'] : "";
        $w = isset($_GET['w']) ? $_GET['w'] : "";
        $h = isset($_GET['h']) ? $_GET['h'] : "";
        $thumb = explode(".", $file);
        $thumbExt = $thumb[count($thumb) - 1];
        $file_path = realpath($media_dir . $file);
        //test_array(array("file"=>$file,"ext"=>$thumbExt,"path"=>$file_path));
        //$file = "Folder 1/Folder 1.2/Folder 1.2.2/p16mv2glf21jac1tf51egb1nb51t423_thumb.jpg";
        if (file_exists($file_path)) {
            //test_array($file_path);
            $thumb = new Image($file, false, $media_dir . "/");
            $thumb->resize($w, $h);
            $thumb->render();
        }
        $showthumb = true;
    } else {
        if ($section == "do_file_rename") {
            $old = isset($_REQUEST['old']) ? $_REQUEST['old'] : "";
            $new = isset($_REQUEST['new']) ? $_REQUEST['new'] : "";
            if ($new == "") {
                test_array(array("error" => "No filename specified"));
            }
            $targetDir = realpath($media_dir . $folder);
            $old_parts = explode(".", $old);
            $old_ext = $old_parts[count($old_parts) - 1];
            $new_parts = explode(".", $new);
            $new_ext = $new_parts[count($new_parts) - 1];
            if (count($new_parts) <= 1) {
Example #22
0
 protected function _do_watermark(Image $image, $offset_x, $offset_y, $opacity)
 {
     // Convert the Image intance into an Imagick instance
     $watermark = new Imagick();
     $watermark->readImageBlob($image->render(), $image->file);
     if ($watermark->getImageAlphaChannel() !== Imagick::ALPHACHANNEL_ACTIVATE) {
         // Force the image to have an alpha channel
         $watermark->setImageAlphaChannel(Imagick::ALPHACHANNEL_OPAQUE);
     }
     if ($opacity < 100) {
         // NOTE: Using setImageOpacity will destroy current alpha channels!
         $watermark->evaluateImage(Imagick::EVALUATE_MULTIPLY, $opacity / 100, Imagick::CHANNEL_ALPHA);
     }
     // Match the colorspace between the two images before compositing
     // $watermark->setColorspace($this->im->getColorspace());
     // Apply the watermark to the image
     return $this->im->compositeImage($watermark, Imagick::COMPOSITE_DISSOLVE, $offset_x, $offset_y);
 }
Example #23
0
 function image_thumbnail($f3)
 {
     // Get Image
     $image = \R::findOne('images', 'tools_id=? AND thumb=1', array($this->D->id));
     if ($image) {
         if (!file_exists($cached = 'tmp/thumb/' . $image->url)) {
             if (!file_exists($filename = $this->upload_dir() . $image->url)) {
                 throw new \Exception('Could not find image');
             }
             $img = new \Image($filename);
             $img->resize(200, 200);
             file_put_contents($cached, $img->dump('jpeg'));
         }
         $web = \Web::instance();
         $web->send($cached, null, 0, false);
     } else {
         $img = new \Image();
         $img->identicon($this->D->name, 200);
         $img->render('jpeg');
     }
 }