public function imageAction()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $id = (int) $request->getQuery('id');
     $w = (int) $request->getQuery('w');
     $h = (int) $request->getQuery('h');
     $hash = $request->getQuery('hash');
     $realHash = DatabaseObject_BlogPostImage::GetImageHash($id, $w, $h);
     $this->_helper->viewRenderer->setNoRender();
     $image = new DatabaseObject_BlogPostImage($this->db);
     if ($hash != $realHash || !$image->load($id)) {
         $response->setHttpResponseCode(404);
         return;
     }
     try {
         $fullpath = $image->createThumbnail($w, $h);
     } catch (Exception $ex) {
         $fullpath = $image->getFullPath();
     }
     $info = getImageSize($fullpath);
     $response->setHeader('content-type', $info['mime']);
     $response->setHeader('content-length', filesize($fullpath));
     echo file_get_contents($fullpath);
 }
Example #2
0
function gerar_tumbs_real($t_x, $t_y, $qualidade, $c_original, $c_final)
{
    $thumbnail = imagecreatetruecolor($t_x, $t_y);
    $original = $c_original;
    $igInfo = getImageSize($c_original);
    switch ($igInfo['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF) {
                $originalimage = imageCreateFromGIF($original);
            } else {
                $ermsg = MSG_GIF_NOT_COMPATIBLE . '<br />';
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG) {
                $originalimage = imageCreateFromJPEG($original);
            } else {
                $ermsg = MSG_JPG_NOT_COMPATIBLE . '<br />';
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG) {
                $originalimage = imageCreateFromPNG($original);
            } else {
                $ermsg = MSG_PNG_NOT_COMPATIBLE . '<br />';
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP) {
                $originalimage = imageCreateFromWBMP($original);
            } else {
                $ermsg = MSG_WBMP_NOT_COMPATIBLE . '<br />';
            }
            break;
        default:
            $ermsg = $igInfo['mime'] . MSG_FORMAT_NOT_COMPATIBLE . '<br />';
            break;
    }
    $nLargura = $igInfo[0];
    $nAltura = $igInfo[1];
    if ($nLargura > $t_x and $nAltura > $t_y) {
        if ($t_x <= $t_y) {
            $nLargura = (int) ($igInfo[0] * $t_y / $igInfo[1]);
            $nAltura = $t_y;
        } else {
            $nLargura = $t_x;
            $nAltura = (int) ($igInfo[1] * $t_x / $igInfo[0]);
            if ($nAltura < $t_y) {
                $nLargura = (int) ($igInfo[0] * $t_y / $igInfo[1]);
                $nAltura = $t_y;
            }
        }
    }
    $x_pos = $t_x / 2 - $nLargura / 2;
    $y_pos = $t_y / 2 - $nAltura / 2;
    imagecopyresampled($thumbnail, $originalimage, $x_pos, $y_pos, 0, 0, $nLargura, $nAltura, $igInfo[0], $igInfo[1]);
    imagejpeg($thumbnail, $c_final, $qualidade);
    imagedestroy($thumbnail);
    return 'ok';
}
Example #3
0
 /**
  * Action - image
  * display images in the predetermined size or in the natural size
  *
  * Access to the action is possible in the following paths:
  * - /utility/image
  *
  * @return void
  */
 public function imageAction()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $username = $request->getQuery('username');
     $id = (int) $request->getQuery('id');
     $w = (int) $request->getQuery('w');
     $h = (int) $request->getQuery('h');
     $hash = $request->getQuery('hash');
     $realHash = Default_Model_DbTable_BlogPostImage::GetImageHash($id, $w, $h);
     // disable autorendering since we're outputting an image
     $this->_helper->viewRenderer->setNoRender();
     $image = new Default_Model_DbTable_BlogPostImage($this->db);
     if ($hash != $realHash || !$image->load($id)) {
         // image not found
         $response->setHttpResponseCode(404);
         return;
     }
     try {
         $fullpath = $image->createThumbnail($w, $h, $username);
     } catch (Exception $ex) {
         $fullpath = $image->getFullPath($username);
     }
     $info = getImageSize($fullpath);
     $response->setHeader('content-type', $info['mime']);
     $response->setHeader('content-length', filesize($fullpath));
     echo file_get_contents($fullpath);
 }
Example #4
0
 function load()
 {
     if ($this->loaded) {
         return true;
     }
     //$size = $this->get_size();
     //if (!$size) throw new exception("Failed loading image");
     list($this->w, $this->h, $this->type) = getImageSize($this->src);
     switch ($this->type) {
         case 1:
             $this->img = imageCreateFromGif($this->src);
             break;
         case 2:
             $this->img = imageCreateFromJpeg($this->src);
             break;
         case 3:
             $this->img = imageCreateFromPng($this->src);
             break;
         default:
             throw new exception("Unsuported image type");
             break;
     }
     $this->loaded = true;
     return true;
 }
Example #5
0
 /**
  * Initialize a layer from a given image path
  * 
  * From an upload form, you can give the "tmp_name" path
  * 
  * @param string $path
  * 
  * @return ImageWorkshopLayer
  */
 public static function initFromPath($path)
 {
     if (file_exists($path) && !is_dir($path)) {
         if (!is_readable($path)) {
             throw new ImageWorkshopException('Can\'t open the file at "' . $path . '" : file is not writable, did you check permissions (755 / 777) ?', static::ERROR_NOT_WRITABLE_FILE);
         }
         $imageSizeInfos = @getImageSize($path);
         $mimeContentType = explode('/', $imageSizeInfos['mime']);
         if (!$mimeContentType || !array_key_exists(1, $mimeContentType)) {
             throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
         }
         $mimeContentType = $mimeContentType[1];
         switch ($mimeContentType) {
             case 'jpeg':
                 $image = imageCreateFromJPEG($path);
                 break;
             case 'gif':
                 $image = imageCreateFromGIF($path);
                 break;
             case 'png':
                 $image = imageCreateFromPNG($path);
                 break;
             default:
                 throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
                 break;
         }
         return new ImageWorkshopLayer($image);
     }
     throw new ImageWorkshopException('No such file found at "' . $path . '"', static::ERROR_IMAGE_NOT_FOUND);
 }
Example #6
0
 public function __construct($path)
 {
     list($this->width, $this->height, $this->type) = @getImageSize($path);
     if ($this->type == IMAGETYPE_JPEG) {
         $this->image = imageCreateFromJPEG($path);
         $this->extension = 'jpg';
         if (function_exists('exif_read_data')) {
             $this->exif = exif_read_data($path);
         }
         $this->rotateToExifOrientation();
     } else {
         if ($this->type == IMAGETYPE_PNG) {
             $this->image = imageCreateFromPNG($path);
             $this->extension = 'png';
         } else {
             if ($this->type == IMAGETYPE_GIF) {
                 $this->image = imageCreateFromGIF($path);
                 $this->extension = 'gif';
             }
         }
     }
     if ($this->image) {
         $this->valid = true;
     }
 }
 /**
  * Returns content of a file. If it's an image the content of the file is not returned but rather an image tag is.
  * This method is taken from tslib_content
  * TODO: cache result
  *
  * @param string The filename, being a TypoScript resource data type or a FAL-Reference (file:123)
  * @param string Additional parameters (attributes). Default is empty alt and title tags.
  * @return string If jpg,gif,jpeg,png: returns image_tag with picture in. If html,txt: returns content string
  * @see FILE()
  */
 public static function getFileResource($fName, $options = array())
 {
     if (!(is_object($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE']->tmpl))) {
         tx_rnbase::load('tx_rnbase_util_Misc');
         tx_rnbase_util_Misc::prepareTSFE(array('force' => TRUE));
     }
     if (self::isFALReference($fName)) {
         /** @var FileRepository $fileRepository */
         $fileRepository = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
         $fileObject = $fileRepository->findByUid(intval(substr($fName, 5)));
         $incFile = is_object($fileObject) ? $fileObject->getForLocalProcessing(FALSE) : FALSE;
     } else {
         $incFile = self::getFileName($fName);
     }
     if ($incFile) {
         // Im BE muss ein absoluter Pfad verwendet werden
         $fullPath = TYPO3_MODE == 'BE' ? PATH_site . $incFile : $incFile;
         $utility = tx_rnbase_util_Typo3Classes::getGeneralUtilityClass();
         $fileinfo = $utility::split_fileref($incFile);
         if ($utility::inList('jpg,gif,jpeg,png', $fileinfo['fileext'])) {
             $imgFile = $incFile;
             $imgInfo = @getImageSize($imgFile);
             $addParams = isset($options['addparams']) ? $options['addparams'] : 'alt="" title=""';
             $ret = '<img src="' . $GLOBALS['TSFE']->absRefPrefix . $imgFile . '" width="' . $imgInfo[0] . '" height="' . $imgInfo[1] . '"' . self::getBorderAttr(' border="0"') . ' ' . $addParams . ' />';
         } elseif (file_exists($fullPath) && filesize($fullPath) < 1024 * 1024) {
             $ret = @file_get_contents($fullPath);
             $subpart = isset($options['subpart']) ? $options['subpart'] : '';
             if ($subpart) {
                 tx_rnbase::load('tx_rnbase_util_Templates');
                 $ret = tx_rnbase_util_Templates::getSubpart($ret, $subpart);
             }
         }
     }
     return $ret;
 }
 private function _getImageResource($image_file, $save = FALSE)
 {
     $image_info = getImageSize($image_file);
     if ($save) {
         $this->_image_mime = $image_info['mime'];
     }
     switch ($image_info['mime']) {
         case 'image/gif':
             if ($save) {
                 $this->_image_type = 'gif';
             }
             $img_rs = imageCreateFromGIF($image_file);
             break;
         case 'image/jpeg':
             if ($save) {
                 $this->_image_type = 'jpeg';
             }
             $img_rs = imageCreateFromJPEG($image_file);
             break;
         case 'image/png':
             if ($save) {
                 $this->_image_type = 'png';
             }
             $img_rs = imageCreateFromPNG($image_file);
             imageAlphaBlending($img_rs, TRUE);
             imageSaveAlpha($img_rs, TRUE);
             break;
     }
     return $img_rs;
 }
 /**
  * Creates a new smiley.
  * 
  * @return	Smiley		new smiley
  */
 public static function create($filename, $destination, $field, $title = null, $code = null, $showOrder = 0, $smileyCategoryID = 0)
 {
     if (!file_exists($filename)) {
         throw new UserInputException($field, 'notFound');
     }
     if (!getImageSize($filename)) {
         throw new UserInputException($field, 'noValidImage');
     }
     // copy
     if ($filename != $destination && !copy($filename, $destination)) {
         throw new UserInputException($field, 'copyFailed');
     }
     // set permissions
     @chmod($destination, 0666);
     // generate title & code by filename
     $name = preg_replace('/\\.[^\\.]+$/', '', basename($destination));
     if ($title === null) {
         $title = $name;
     }
     if ($code === null) {
         $code = ':' . $name . ':';
     }
     // save data
     $smileyID = self::insert(str_replace(WCF_DIR, '', $destination), $code, array('smileyTitle' => $title, 'showOrder' => $showOrder, 'smileyCategoryID' => $smileyCategoryID));
     // get editor object
     $smiley = new SmileyEditor($smileyID);
     // save position
     $smiley->addPosition($smileyCategoryID, $showOrder);
     // save data
     return $smiley;
 }
Example #10
0
 protected function get_any_type($srcpath)
 {
     try {
         $this->check_file($srcpath);
         $srcSize = getImageSize($srcpath);
         switch ($srcSize[2]) {
             case 1:
                 $img = imageCreateFromGif($srcpath);
                 break;
             case 2:
                 $img = imageCreateFromJpeg($srcpath);
                 break;
             case 3:
                 $img = imageCreateFromPng($srcpath);
                 break;
             default:
                 throw new Imgdexception('not possible to get any type - srcpath:' . $srcpath);
                 break;
         }
         $image['width'] = $srcSize[0];
         $image['height'] = $srcSize[1];
         $image['img'] = $img;
         return $image;
     } catch (Imgdexception $e) {
         $e->print_debug(__FILE__, __LINE__);
         return false;
     }
 }
 /** check if image has correct width and height (0 for unlimited values) 
  * 
  * @example   $rule_image_3  = new NetefxValidatorRuleFUNCTION("Image",  "image width at least 10, image height at most 500", 'error', 
  * 																array('NetefxValidatorLibraryFile', 'check_image_size', 
  * 																	array('field'  => 'Image', 'minWidth' => 10, 'maxWidth' => 0, 'minHeight' => 0, 'maxHeight' => 500)));
  */
 static function check_image_size($data, $args)
 {
     $field = $args["field"];
     $arr_file = $data[$field];
     if ($arr_file["tmp_name"]) {
         $image_size = getImageSize($arr_file["tmp_name"]);
         if ($image_size) {
             $width = $image_size[0];
             $height = $image_size[1];
             $minWidth = $args["minWidth"];
             $minHeight = $args["minHeight"];
             $maxWidth = $args["maxWidth"];
             $maxHeight = $args["maxHeight"];
             if ($minWidth and $width < $minWidth) {
                 return false;
             }
             if ($minHeight and $height < $minHeight) {
                 return false;
             }
             if ($maxWidth and $width > $maxWidth) {
                 return false;
             }
             if ($maxHeight and $height > $maxHeight) {
                 return false;
             }
         }
     }
     return true;
 }
Example #12
0
function image_createThumb($src, $dest, $maxWidth, $maxHeight, $quality = 75)
{
    if (file_exists($src) && isset($dest)) {
        // path info
        $destInfo = pathInfo($dest);
        // image src size
        $srcSize = getImageSize($src);
        // image dest size $destSize[0] = width, $destSize[1] = height
        $srcRatio = $srcSize[0] / $srcSize[1];
        // width/height ratio
        $destRatio = $maxWidth / $maxHeight;
        if ($destRatio > $srcRatio) {
            $destSize[1] = $maxHeight;
            $destSize[0] = $maxHeight * $srcRatio;
        } else {
            $destSize[0] = $maxWidth;
            $destSize[1] = $maxWidth / $srcRatio;
        }
        // path rectification
        if ($destInfo['extension'] == "gif") {
            $dest = substr_replace($dest, 'jpg', -3);
        }
        // true color image, with anti-aliasing
        $destImage = imageCreateTrueColor($destSize[0], $destSize[1]);
        //       imageAntiAlias($destImage,true);
        // src image
        switch ($srcSize[2]) {
            case 1:
                //GIF
                $srcImage = imageCreateFromGif($src);
                break;
            case 2:
                //JPEG
                $srcImage = imageCreateFromJpeg($src);
                break;
            case 3:
                //PNG
                $srcImage = imageCreateFromPng($src);
                break;
            default:
                return false;
                break;
        }
        // resampling
        imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destSize[0], $destSize[1], $srcSize[0], $srcSize[1]);
        // generating image
        switch ($srcSize[2]) {
            case 1:
            case 2:
                imageJpeg($destImage, $dest, $quality);
                break;
            case 3:
                imagePng($destImage, $dest);
                break;
        }
        return true;
    } else {
        return 'No such File';
    }
}
Example #13
0
function create_thumb($src_file, $thumb_file, $t_width, $t_height)
{
    if (!file_exists($src_file)) {
        return false;
    }
    $src_info = getImageSize($src_file);
    //如果来源图像小于或等于缩略图则拷贝源图像作为缩略图
    if ($src_info[0] <= $t_width && $src_info[1] <= $t_height) {
        if (!copy($src_file, $thumb_file)) {
            return false;
        }
        return true;
    }
    //按比例计算缩略图大小
    if ($src_info[0] - $t_width > $src_info[1] - $t_height) {
        $t_height = $t_width / $src_info[0] * $src_info[1];
    } else {
        $t_width = $t_height / $src_info[1] * $src_info[0];
    }
    //取得文件扩展名
    $fileext = get_ext($src_file);
    switch ($fileext) {
        case 'jpg':
            $src_img = ImageCreateFromJPEG($src_file);
            break;
        case 'png':
            $src_img = ImageCreateFromPNG($src_file);
            break;
        case 'gif':
            $src_img = ImageCreateFromGIF($src_file);
            break;
    }
    //创建一个真彩色的缩略图像
    $thumb_img = @ImageCreateTrueColor($t_width, $t_height);
    //ImageCopyResampled函数拷贝的图像平滑度较好,优先考虑
    if (function_exists('imagecopyresampled')) {
        @ImageCopyResampled($thumb_img, $src_img, 0, 0, 0, 0, $t_width, $t_height, $src_info[0], $src_info[1]);
    } else {
        @ImageCopyResized($thumb_img, $src_img, 0, 0, 0, 0, $t_width, $t_height, $src_info[0], $src_info[1]);
    }
    //生成缩略图
    switch ($fileext) {
        case 'jpg':
            ImageJPEG($thumb_img, $thumb_file);
            break;
        case 'gif':
            ImageGIF($thumb_img, $thumb_file);
            break;
        case 'png':
            ImagePNG($thumb_img, $thumb_file);
            break;
    }
    //销毁临时图像
    @ImageDestroy($src_img);
    @ImageDestroy($thumb_img);
    return true;
}
Example #14
0
 static function get_image_size($filename)
 {
     if (isset(self::$gisz[$filename])) {
         return self::$gisz[$filename];
     }
     $sz = @getImageSize($filename);
     self::$gisz[$filename] = $sz;
     return $sz;
 }
Example #15
0
function create_thumb($path, $thumb_path, $width = THUMB_WIDTH, $height = THUMB_HEIGHT)
{
    $image_info = getImageSize($path);
    // see EXIF for faster way
    switch ($image_info['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF) {
                // not the same as IMAGETYPE
                $o_im = @imageCreateFromGIF($path);
            } else {
                throw new Exception('GIF images are not supported');
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG) {
                $o_im = @imageCreateFromJPEG($path);
            } else {
                throw new Exception('JPEG images are not supported');
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG) {
                $o_im = @imageCreateFromPNG($path);
            } else {
                throw new Exception('PNG images are not supported');
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP) {
                $o_im = @imageCreateFromWBMP($path);
            } else {
                throw new Exception('WBMP images are not supported');
            }
            break;
        default:
            throw new Exception($image_info['mime'] . ' images are not supported');
            break;
    }
    list($o_wd, $o_ht, $html_dimension_string) = $image_info;
    $ratio = $o_wd / $o_ht;
    $t_ht = $width;
    $t_wd = $height;
    if (1 > $ratio) {
        $t_wd = round($o_wd * $t_wd / $o_ht);
    } else {
        $t_ht = round($o_ht * $t_ht / $o_wd);
    }
    $t_wd = $t_wd < 1 ? 1 : $t_wd;
    $t_ht = $t_ht < 1 ? 1 : $t_ht;
    $t_im = imageCreateTrueColor($t_wd, $t_ht);
    imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
    imagejpeg($t_im, $thumb_path, 85);
    chmod($thumb_path, 0664);
    imageDestroy($o_im);
    imageDestroy($t_im);
    return array($t_wd, $t_ht);
}
Example #16
0
function thumbnail($image, $width, $height, $extension)
{
    $data = getImageSize($image);
    $imageInfo["width"] = $data[0];
    $imageInfo["height"] = $data[1];
    $imageInfo["type"] = $data[2];
    switch ($imageInfo["type"]) {
        case 1:
            $img = imagecreatefromgif($image);
            break;
        case 2:
            $img = imageCreatefromjpeg($image);
            break;
        case 3:
            $img = imageCreatefrompng($image);
            break;
        default:
            return false;
    }
    $size["width"] = $imageInfo["width"];
    $size["height"] = $imageInfo["height"];
    if ($width < $imageInfo["width"]) {
        $size["width"] = $width;
    }
    if ($height < $imageInfo["height"]) {
        $size["height"] = $height;
    }
    if ($imageInfo["width"] * $size["width"] > $imageInfo["height"] * $size["height"]) {
        $size["height"] = round($imageInfo["height"] * $size["width"] / $imageInfo["width"]);
    } else {
        $size["width"] = round($imageInfo["width"] * $size["height"] / $imageInfo["height"]);
    }
    $newImg = imagecreatetruecolor($size["width"], $size["height"]);
    $otsc = imagecolortransparent($img);
    if ($otsc >= 0 && $otsc <= imagecolorstotal($img)) {
        $tran = imagecolorsforindex($img, $otsc);
        $newt = imagecolorallocate($newImg, $tran["red"], $tran["green"], $tran["blue"]);
        imagefill($newImg, 0, 0, $newt);
        imagecolortransparent($newImg, $newt);
    }
    imagecopyresized($newImg, $img, 0, 0, 0, 0, $size["width"], $size["height"], $imageInfo["width"], $imageInfo["height"]);
    imagedestroy($img);
    $newName = str_replace('.', $extension . '.', $image);
    switch ($imageInfo["type"]) {
        case 1:
            $result = imageGif($newImg, $newName);
            break;
        case 2:
            $result = imageJPEG($newImg, $newName);
            break;
        case 3:
            $result = imagepng($newImg, $newName);
            break;
    }
    imagedestroy($newImg);
}
Example #17
0
 public function __construct($file)
 {
     $this->setFileName($file['name']);
     $this->setType($file['type']);
     $this->setSize($file['size']);
     $this->setTempName($file['tmp_name']);
     $dimensions = getImageSize($this->getTempName());
     $this->setWidth($dimensions[0]);
     $this->setHeight($dimensions[1]);
 }
Example #18
0
 /**
  * {@inheritDoc}
  */
 public static function createFromFile($filename)
 {
     $data = @getImageSize($filename);
     if ($data && is_array($data)) {
         $function = 'imagecreatefrom' . image_type_to_extension($data[2], false);
         if (function_exists($function)) {
             return new static($function($filename), $data[2]);
         }
     }
     throw new ImageException("The image file '{$filename}' cannot be loaded");
 }
Example #19
0
function downLoadPic($url, $dir = "downloads/")
{
    $info = @getImageSize($url);
    if ($info === false) {
        return;
    }
    $suffix = image_type_to_extension($info[2], false);
    $img = file_get_contents($url);
    $filename = uniqid() . '.' . $suffix;
    file_put_contents($dir . $filename, $img);
}
Example #20
0
 public function MakeThumbnail($o_file, $fileName, $quality, $width, $height)
 {
     $image_info = getImageSize($o_file);
     switch ($image_info['mime']) {
         case 'image/gif':
             if (imagetypes() & IMG_GIF) {
                 // not the same as IMAGETYPE
                 $o_im = imageCreateFromGIF($o_file);
             }
             break;
         case 'image/jpeg':
             if (imagetypes() & IMG_JPG) {
                 $o_im = imageCreateFromJPEG($o_file);
             }
             break;
         case 'image/png':
             if (imagetypes() & IMG_PNG) {
                 $o_im = imageCreateFromPNG($o_file);
             }
             break;
         case 'image/wbmp':
             if (imagetypes() & IMG_WBMP) {
                 $o_im = imageCreateFromWBMP($o_file);
             }
             break;
         default:
             break;
     }
     $o_wd = imagesx($o_im);
     $o_ht = imagesy($o_im);
     // thumbnail width = target * original width / original height
     if ($o_ht > $o_wd) {
         $t_wd = round($o_wd * $height / $o_ht);
         $t_ht = $height;
     }
     if ($o_ht < $o_wd) {
         $t_ht = round($o_ht * $width / $o_wd);
         $t_wd = $width;
     }
     if ($t_ht > $height) {
         $t_wd = round($o_wd * $height / $o_ht);
         $t_ht = $height;
     }
     $t_im = imageCreateTrueColor($t_wd, $t_ht);
     imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
     imageJPEG($t_im, $fileName, 100);
     imageDestroy($o_im);
     imageDestroy($t_im);
     return true;
 }
Example #21
0
 /**
  * Returns the MIME content type of an uploaded file.
  * @return string
  */
 public function getContentType()
 {
     if ($this->isOk() && $this->realType === NULL) {
         if (extension_loaded('fileinfo')) {
             $this->realType = finfo_file(finfo_open(FILEINFO_MIME), $this->tmpName);
         } elseif (function_exists('mime_content_type')) {
             $this->realType = mime_content_type($this->tmpName);
         } else {
             $info = getImageSize($this->tmpName);
             $this->realType = isset($info['mime']) ? $info['mime'] : $this->type;
         }
     }
     return $this->realType;
 }
Example #22
0
function dothumb($picpath)
{
    $arr = explode('/', $picpath);
    $filename = array_pop($arr);
    $big_name = get_big_name($filename);
    $imginfo = getImageSize($picpath);
    $imgw = $imginfo[0];
    $imgh = $imginfo[1];
    $image = new \Think\Image();
    $image->open($picpath);
    $image->save('./Public/allimage/' . $big_name);
    $image->thumb(300, 300, \Think\Image::IMAGE_THUMB_SCALE)->save('./Public/allimage/' . $filename);
    unlink($picpath);
    return $filename;
}
Example #23
0
function isLarge($target, $maxX, $maxY)
{
    if (!file_exists($target)) {
        return false;
    }
    $size = getImageSize($target);
    $sx = $size[0];
    $sy = $size[1];
    if (strpos($maxX, "%") && strpos($maxY, "%")) {
        return false;
    }
    if ($sx > $maxX || $sy > $maxY) {
        return true;
    } else {
        return false;
    }
}
 function __construct($path = '', $image_src = '')
 {
     $this->path = $path;
     $this->image_src = $image_src;
     $this->overwrite = true;
     if ($this->image_src) {
         $check = getImageSize($this->path . $this->image_src);
         $this->width = $check[0];
         $this->height = $check[1];
         $this->type = $check[2];
     }
     $this->valid_types[] = "image/pjpeg";
     $this->valid_types[] = "image/jpeg";
     $this->valid_types[] = "image/jpg";
     $this->valid_types[] = "image/gif";
     $this->valid_types[] = "image/png";
 }
 /** Returns the size of the picture based on a wished size. */
 function getSmartSize($size)
 {
     $imagedata = getImageSize($this->getPath());
     if ($imagedata[0] >= $imagedata[1]) {
         $width = $size;
     } else {
         $height = $size;
     }
     if ($width) {
         $w = $width;
         $h = round($imagedata[1] / ($imagedata[0] / $width));
     }
     if ($height) {
         $w = round($imagedata[0] / ($imagedata[1] / $height));
         $h = $height;
     }
     return array("width" => $w, "height" => $h);
 }
Example #26
0
 /**
  * @see	\wcf\system\image\adapter\IImageAdapter::loadFile()
  */
 public function loadFile($file)
 {
     list($this->width, $this->height, $this->type) = getImageSize($file);
     switch ($this->type) {
         case IMAGETYPE_GIF:
             $this->image = imageCreateFromGif($file);
             break;
         case IMAGETYPE_JPEG:
             $this->image = imageCreateFromJpeg($file);
             break;
         case IMAGETYPE_PNG:
             $this->image = imageCreateFromPng($file);
             break;
         default:
             throw new SystemException("Could not read image '" . $file . "', format is not recognized.");
             break;
     }
 }
Example #27
0
 public function candidateImageSize()
 {
     //common code for checking the size of the candidate image
     // first we normalize the url to an absolute url
     $this->normalizeCandidateImageUrl();
     // then we check and return the dimensions of the candidate image size;
     /*if ($this->fastExtraction) {
     			echo 'Extracting dimensions using fast extraction' . PHP_EOL;
     			$FastImageSize = new \FastImageSize\FastImageSize();
     			$imageSize = $FastImageSize->getImageSize($this->candidateImage);
     			return $imageSize;
     		}*/
     $image = @getImageSize($this->candidateImage);
     $imageSize = [];
     $imageSize['width'] = $image[0];
     $imageSize['height'] = $image[1];
     return $imageSize;
 }
 public function loadFile($file)
 {
     list(, , $type) = @getImageSize($file);
     switch ($type) {
         case IMAGETYPE_GIF:
             $this->resource = imagecreatefromgif($file);
             break;
         case IMAGETYPE_JPEG:
             $this->resource = imagecreatefromjpeg($file);
             break;
         case IMAGETYPE_PNG:
             $this->resource = imagecreatefrompng($file);
             break;
         default:
             throw new \RuntimeException("Image '" . $file . "' is not readable or does not exists.");
             break;
     }
 }
Example #29
0
 /**
  * __set 
  * 
  * @param mixed $propertyName 
  * @param mixed $propertyValue 
  * @throws ezcBaseValueException
  *          If a submitted parameter was out of range or type.
  * @throws ezcBasePropertyNotFoundException
  *          If a the value for the property options is not an instance of
  * @return void
  * @ignore
  */
 public function __set($propertyName, $propertyValue)
 {
     switch ($propertyName) {
         case 'image':
             // Check for existance of file
             if (!is_file($propertyValue) || !is_readable($propertyValue)) {
                 throw new ezcBaseFileNotFoundException($propertyValue);
             }
             // Check for beeing an image file
             $data = getImageSize($propertyValue);
             if ($data === false) {
                 throw new ezcGraphInvalidImageFileException($propertyValue);
             }
             // SWF files are useless..
             if ($data[2] === 4) {
                 throw new ezcGraphInvalidImageFileException('We cant use SWF files like <' . $propertyValue . '>.');
             }
             $this->properties['image'] = $propertyValue;
             break;
         case 'repeat':
             if ($propertyValue >= 0 && $propertyValue <= 3) {
                 $this->properties['repeat'] = (int) $propertyValue;
             } else {
                 throw new ezcBaseValueException($propertyName, $propertyValue, '0 <= int <= 3');
             }
             break;
         case 'position':
             // Overwrite parent position setter, to be able to use
             // combination of positions like
             //      ezcGraph::TOP | ezcGraph::CENTER
             if (is_int($propertyValue)) {
                 $this->properties['position'] = $propertyValue;
             } else {
                 throw new ezcBaseValueException($propertyName, $propertyValue, 'integer');
             }
             break;
         case 'color':
             // Use color as an alias to set background color for background
             $this->__set('background', $propertyValue);
             break;
         default:
             return parent::__set($propertyName, $propertyValue);
     }
 }
Example #30
0
 /**
  * ฟังก์ชั่นตรวจสอบไฟล์อัปโหลดว่าเป็นรูปภาพหรือไม่
  *
  * @param array $excepts ชนิดของไฟล์ที่ยอมรับเช่น array('jpg', 'gif', 'png')
  * @param array $file_upload รับค่ามาจาก $_FILES
  * @return array|bool คืนค่าแอเรย์ [width, height, mime] ของรูปภาพ หรือ  false ถ้าไม่ใช่รูปภาพ
  */
 public static function isImage($excepts, $file_upload)
 {
     // ext
     $imageinfo = explode('.', $file_upload['name']);
     $imageinfo = array('ext' => strtolower(end($imageinfo)));
     if (in_array($imageinfo['ext'], $excepts)) {
         // Exif
         $info = getImageSize($file_upload['tmp_name']);
         if ($info[0] == 0 || $info[1] == 0 || !Mime::check($excepts, $info['mime'])) {
             return false;
         } else {
             $imageinfo['width'] = $info[0];
             $imageinfo['height'] = $info[1];
             $imageinfo['mime'] = $info['mime'];
             return $imageinfo;
         }
     } else {
         return false;
     }
 }