/**
  * Return the file properties of a specific file
  *
  * @param string $filePath
  *
  * @return array
  */
 public function getProperties($filePath)
 {
     $properties = array();
     $info = @getimagesize($filePath);
     $properties['width'] = @$info[0];
     $properties['height'] = @$info[1];
     $properties['type'] = @$info[2];
     $properties['mime'] = @$info['mime'];
     if ($info[0] > 60 || $info[1] > 60) {
         $dimensions = MediaHelper::imageResize($info[0], $info[1], 60);
         $properties['width_60'] = $dimensions[0];
         $properties['height_60'] = $dimensions[1];
     } else {
         $properties['width_60'] = $properties['width'];
         $properties['height_60'] = $properties['height'];
     }
     if ($info[0] > 16 || $info[1] > 16) {
         $dimensions = MediaHelper::imageResize($info[0], $info[1], 16);
         $properties['width_16'] = $dimensions[0];
         $properties['height_16'] = $dimensions[1];
     } else {
         $properties['width_16'] = $properties['width'];
         $properties['height_16'] = $properties['height'];
     }
     return $properties;
 }
	function getThumbnailDimension($path, $w, $h)
	{
		$dim = array('w' => $w, 'h' => $h);
		if ($w && $h || (!$w && !$h)) return $dim;

		if (@is_readable($path) && function_exists('getimagesize'))
		{
			$info = @getimagesize($path);
			if (!empty($info) && count($info) > 1)
			{
				if (empty($w))
				{
					$w = round($h * $info[0] / $info[1]);
					$dim['w'] = $w;
				}
				else
				{
					$h = round($w * $info[1] / $info[0]);
					$dim['h'] = $h;
				}
			}
		}
		
		return $dim;
	}
Example #3
1
	public function GenerateLogo()
	{
		$this->NewLogo($this->FileType); // defaults to png. can use jpg or gif as well

		$this->FontPath = dirname(__FILE__) . '/fonts/';
		$this->ImagePath = dirname(__FILE__) . '/';
		$this->SetBackgroundImage('back.png');
		$size = getimagesize(dirname(__FILE__)."/back.png");
		$imageHeight = $size['1'];

		if(strlen($this->Text[0]) > 0) {
			// AddText() - text, font, fontcolor, fontSize (pt), x, y, center on this width
			$text_position = $this->AddText($this->Text[0], 'xt.otf', 'd0a642', 15, 43, 20);
			$top_right = $text_position['top_right_x'];
		}
		else {
			$top_right = 0;
		}

		if(strlen($this->Text[1]) > 0) {
			// put in our second bit of text
			$text_position2 = $this->AddText($this->Text[1], 'xt.otf', 'ffffff', 45, 5, 46);
			$top_right = max($top_right, $text_position2['top_right_x']);
		}

		if(strlen($this->Text[2]) > 0) {
			// put in our third bit of text
			$text_position3 = $this->AddText($this->Text[2], 'xt.otf', 'b49a5d', 20, 75, 100);
			$top_right = max($top_right, $text_position3['top_right_x']);
		}
		$this->SetImageSize($top_right+20, $imageHeight);
		$this->CropImage = true;

		return $this->MakeLogo();
	}
Example #4
1
 function imageDualResize($filename, $cleanFilename, $wtarget, $htarget)
 {
     if (!file_exists($cleanFilename)) {
         $dims = getimagesize($filename);
         $width = $dims[0];
         $height = $dims[1];
         while ($width > $wtarget || $height > $htarget) {
             if ($width > $wtarget) {
                 $percentage = $wtarget / $width;
             }
             if ($height > $htarget) {
                 $percentage = $htarget / $height;
             }
             /*if($width > $height)
             		{
             			$percentage = ($target / $width);
             		}
             		else
             		{
             			$percentage = ($target / $height);
             		}*/
             //gets the new value and applies the percentage, then rounds the value
             $width = round($width * $percentage);
             $height = round($height * $percentage);
         }
         $image = new SimpleImage();
         $image->load($filename);
         $image->resize($width, $height);
         $image->save($cleanFilename);
         $image = null;
     }
     //returns the new sizes in html image tag format...this is so you can plug this function inside an image tag and just get the
     return "src=\"{$baseurl}/{$cleanFilename}\"";
 }
Example #5
1
	protected function _validate($context)
	{
		$config = $this->_config;
		$row = $context->caller;

		if (is_uploaded_file($row->file) && $config->restrict && !in_array($row->extension, $config->ignored_extensions->toArray())) 
		{
			if ($row->isImage()) 
			{
				if (getimagesize($row->file) === false) {
					$context->setError(JText::_('WARNINVALIDIMG'));
					return false;
				}
			}
			else 
			{
				$mime = KFactory::get('com://admin/files.database.row.file')->setData(array('path' => $row->file))->mimetype;

				if ($config->check_mime && $mime) 
				{
					if (in_array($mime, $config->illegal_mimetypes->toArray()) || !in_array($mime, $config->allowed_mimetypes->toArray())) {
						$context->setError(JText::_('WARNINVALIDMIME'));
						return false;
					}
				}
				elseif (!$config->authorized) {
					$context->setError(JText::_('WARNNOTADMIN'));
					return false;
				}
			}
		}
	}
Example #6
0
function title_and_caption_not_utf8($meta, $file)
{
    if (!file_exists($file)) {
        return false;
    }
    list(, , $sourceImageType) = getimagesize($file);
    $meta = array();
    if (is_callable('iptcparse')) {
        getimagesize($file, $info);
        if (!empty($info['APP13'])) {
            $iptc = iptcparse($info['APP13']);
            // headline, "A brief synopsis of the caption."
            if (!empty($iptc['2#105'][0])) {
                $meta['title'] = trim($iptc['2#105'][0]);
            } elseif (!empty($iptc['2#005'][0])) {
                $meta['title'] = trim($iptc['2#005'][0]);
            }
            if (!empty($iptc['2#120'][0])) {
                // description / legacy caption
                $caption = trim($iptc['2#120'][0]);
                if (empty($meta['title'])) {
                    // Assume the title is stored in 2:120 if it's short.
                    if (strlen($caption) < 80) {
                        $meta['title'] = $caption;
                    } else {
                        $meta['caption'] = $caption;
                    }
                } elseif ($caption != $meta['title']) {
                    $meta['caption'] = $caption;
                }
            }
        }
    }
    return $meta;
}
Example #7
0
function _thumb($_filename, $_percent)
{
    //生成png标头文件
    header('Content-type: image/png');
    $_n = explode('.', $_filename);
    //获取文件信息,长和高
    list($_width, $_height) = getimagesize($_filename);
    //生成缩微的长和高
    $_new_width = $_width * $_percent;
    $_new_height = $_height * $_percent;
    //创建一个以0.3百分比新长度的画布
    $_new_image = imagecreatetruecolor($_new_width, $_new_height);
    //按照已有的图片创建一个画布
    switch ($_n[1]) {
        case 'jpg':
            $_image = imagecreatefromjpeg($_filename);
            break;
        case 'png':
            $_image = imagecreatefrompng($_filename);
            break;
        case 'gif':
            $_image = imagecreatefrompng($_filename);
            break;
    }
    //将原图采集后重新复制到新图上,就缩略了
    imagecopyresampled($_new_image, $_image, 0, 0, 0, 0, $_new_width, $_new_height, $_width, $_height);
    imagepng($_new_image);
    imagedestroy($_new_image);
    imagedestroy($_image);
}
 /**
  * MÉTODO CONSTRUTOR
  *
  * @author Gibran
  */
 function Imagem($arquivo)
 {
     if (is_file($arquivo)) {
         $this->Arquivo = $arquivo;
         // OBTÉM OS DADOS DA IMAGEM
         $this->ColecaoDados = getimagesize($this->Arquivo);
         // CARREGA A IMAGEM DE ACORDO COM O TIPO
         switch ($this->ColecaoDados[2]) {
             case 1:
                 $this->Recurso = imagecreatefromgif($this->Arquivo);
                 $this->Tipo = "image/gif";
                 break;
             case 2:
                 $this->Recurso = imagecreatefromjpeg($this->Arquivo);
                 $this->Tipo = "image/jpeg";
                 imageinterlace($this->Recurso, true);
                 break;
             case 3:
                 $this->Recurso = imagecreatefrompng($this->Arquivo);
                 $this->Tipo = "image/png";
                 imagealphablending($this->Recurso, false);
                 imagesavealpha($this->Recurso, true);
                 break;
             default:
                 $this->ColecaoDados = null;
                 $this->Recurso = null;
                 $this->Tipo = null;
                 return null;
                 break;
         }
     } else {
         return null;
     }
 }
function cuttingimg($zoom, $fn, $sz)
{
    @mkdir(WUO_ROOT . '/photos/maps');
    $img = imagecreatefrompng(WUO_ROOT . '/photos/maps/0-0-0-' . $fn);
    // получаем идентификатор загруженного изрбражения которое будем резать
    $info = getimagesize(WUO_ROOT . '/photos/maps/0-0-0-' . $fn);
    // получаем в массив информацию об изображении
    $w = $info[0];
    $h = $info[1];
    // ширина и высота исходного изображения
    $sx = round($w / $sz, 0);
    // длинна куска изображения
    $sy = round($h / $sz, 0);
    // высота куска изображения
    $px = 0;
    $py = 0;
    // координаты шага "реза"
    for ($y = 0; $y <= $sz; $y++) {
        for ($x = 0; $x <= $sz; $x++) {
            $imgcropped = imagecreatetruecolor($sx, $sy);
            imagecopy($imgcropped, $img, 0, 0, $px, $py, $sx, $sy);
            imagepng($imgcropped, WUO_ROOT . '/photos/maps/' . $zoom . '-' . $y . '-' . $x . '-' . $fn);
            $px = $px + $sx;
        }
        $px = 0;
        $py = $py + $sy;
    }
}
function mkthumb($img_src, $img_width = "100", $img_height = "100", $folder_scr = "include/files", $des_src = "include/files")
{
    // Größe und Typ ermitteln
    list($src_width, $src_height, $src_typ) = getimagesize($folder_scr . "/" . $img_src);
    if (!$src_typ) {
        return false;
    }
    // calculate new size
    if ($src_width >= $src_height) {
        $new_image_height = $src_height / $src_width * $img_width;
        $new_image_width = $img_width;
        if ($new_image_height > $img_height) {
            $new_image_width = $new_image_width / $new_image_height * $img_height;
            $new_image_height = $img_height;
        }
    } else {
        $new_image_width = $src_width / $src_height * $img_height;
        $new_image_height = $img_height;
        if ($new_image_width > $img_width) {
            $new_image_height = $new_image_height / $new_image_width * $img_width;
            $new_image_width = $img_width;
        }
    }
    // for the case that the thumbnail would be bigger then the original picture
    if ($new_image_height > $src_height) {
        $new_image_width = $new_image_width * $src_height / $new_image_height;
        $new_image_height = $src_height;
    }
    if ($new_image_width > $src_width) {
        $new_image_height = $new_image_height * $new_image_width / $src_width;
        $new_image_width = $src_width;
    }
    if ($src_typ == 1) {
        $image = imagecreatefromgif($folder_scr . "/" . $img_src);
        $new_image = imagecreate($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagegif($new_image, $des_src . "/" . $img_src . "_thumb", 100);
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } elseif ($src_typ == 2) {
        $image = imagecreatefromjpeg($folder_scr . "/" . $img_src);
        $new_image = imagecreatetruecolor($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagejpeg($new_image, $des_src . "/" . $img_src . "_thumb", 100);
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } elseif ($src_typ == 3) {
        $image = imagecreatefrompng($folder_scr . "/" . $img_src);
        $new_image = imagecreatetruecolor($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagepng($new_image, $des_src . "/" . $img_src . "_thumb");
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } else {
        return false;
    }
}
 protected function invokeHandler()
 {
     $specific = array();
     $size = getimagesize($this->file->getAbsPath());
     if ($size !== false) {
         $specific['imagesize'] = $size[0] . ' x ' . $size[1] . ' px';
     } else {
         $specific['imagesize'] = System::getLanguage()->_('Unknown');
     }
     if (extension_loaded('imagick') && class_exists('Imagick')) {
         try {
             $i = new Imagick($this->file->getAbsPath());
             $specific['format'] = $i->getimageformat();
         } catch (Exception $e) {
             Log::handleException($e, false);
             if ($this->file->ext == "svg") {
                 Log::sysLog('ImageHandler', '"librsvg" is not installed. Without it Imagick could not handle .svg files!');
             }
         }
     } else {
         $specific['format'] = System::getLanguage()->_('Unknown');
     }
     $this->smarty->assign('specific', $specific);
     $this->smarty->display('handler/image.tpl');
 }
Example #12
0
/**
 *  Retourne la couleur du pixel en bas a gauche de l'image
 **/
function colorImageBottom($imageName)
{
    // recuperer le type et la taille de l'image
    // Pb sur certains JPG qui retourne ''
    list($imgW, $imgH, $imgTyp) = getimagesize($imageName);
    switch ($imgTyp) {
        case 1:
            $im = imagecreatefromgif($imageName);
            break;
        case 2:
        case ' ':
            $im = imagecreatefromjpeg($imageName);
            break;
        case 3:
            $im = imagecreatefrompng($imageName);
            break;
        default:
            $app = JFactory::getApplication();
            $app->enqueueMessage(JTEXT::_('IMGNAME_ERROR') . '[name=' . $imageName . '] [ type=' . $imgTyp . '] [ format= ' . $imgW . 'x' . $imgH, 'error');
            var_dump(gd_info());
            return "";
    }
    $rgb = imagecolorat($im, 2, $imgH - 2);
    $hex = sprintf("%06X", $rgb);
    return $hex;
}
Example #13
0
 public static function boot()
 {
     parent::boot();
     self::saving(function ($download) {
         $fileName = $download->uploadPath(true) . $download->file;
         if (File::isFile($fileName)) {
             $download->file_size = File::size($fileName);
             // Save file size
             try {
                 $imgData = getimagesize($fileName);
                 // Try to gather infos about the image
             } catch (Exception $e) {
             }
             if (isset($imgData[2]) and $imgData[2]) {
                 $download->is_image = true;
                 /*
                  * Create Thumbnail
                  */
                 $size = 50;
                 InterImage::make($fileName)->resize($size, $size, function ($constraint) {
                     $constraint->aspectRatio();
                 })->save($download->uploadPath(true) . $size . '/' . $download->file);
             }
         }
     });
 }
Example #14
0
 public static function resize($sourcePath, $destPath, $width, $height, $q = 'JPG', $crop = false)
 {
     try {
         $destDir = dirname($destPath);
         if (!is_dir($destDir)) {
             mkdir($destDir, 0777);
         }
         list($max_width, $max_height) = getimagesize($sourcePath);
         $options = array('correctPermissions' => true, 'resizeUp' => true);
         $thumb = Thumbnailer_ThumbLib::create($sourcePath, $options);
         $width_ratio = $max_width / $width;
         $height_ratio = $max_height / $height;
         if ($max_width < $width or $max_width < $height) {
             if ($width_ratio > $height_ratio) {
                 $thumb->resize(0, $height);
             } else {
                 $thumb->resize($width, 0);
             }
             if ($crop) {
                 $thumb->crop(0, 0, $width, $height);
             }
         } else {
             $thumb->resize($width, $height);
         }
         $thumb->save($destPath, $q);
     } catch (Exception $e) {
         $destPath = $e->getMessage();
     }
     return $destPath;
 }
 public function fill_watermark()
 {
     $image = $this->editor->get_image();
     $size = $this->editor->get_size();
     list($mask_width, $mask_height, $mask_type, $mask_attr) = getimagesize($this->args['mask']);
     switch ($mask_type) {
         case 1:
             $mask = imagecreatefromgif($this->args['mask']);
             break;
         case 2:
             $mask = imagecreatefromjpeg($this->args['mask']);
             break;
         case 3:
             $mask = imagecreatefrompng($this->args['mask']);
             break;
     }
     imagealphablending($image, true);
     if (strpos($this->args['position'], 'left') !== false) {
         $left = $this->args['padding'];
     } else {
         $left = $size['width'] - $mask_width - $this->args['padding'];
     }
     if (strpos($this->args['position'], 'top') !== false) {
         $top = $this->args['padding'];
     } else {
         $top = $size['height'] - $mask_height - $this->args['padding'];
     }
     imagecopy($image, $mask, $left, $top, 0, 0, $mask_width, $mask_height);
     $this->editor->update_image($image);
     imagedestroy($mask);
 }
Example #16
0
function printThumbPhotos()
{
    $handle = opendir("images/gallery");
    $x = 0;
    $left = 0;
    $files = array();
    $dimension = array();
    while (($file = readdir($handle)) !== false) {
        if ($file != "." && $file != "..") {
            $thumb = '<li style="left:' . $left . 'px;">';
            $thumb .= '<a href="#picture-feed-box-' . $x . '">';
            $thumb .= '<img height="85" width="126" alt="" src="include/resizeimage.php?filename=' . $file . '&width=85&height=126" />';
            $thumb .= '</a>';
            $thumb .= '</li>';
            $left += 132;
            $x++;
            $dimension = getimagesize("images/gallery/" . $file);
            $files[] = $file;
            $dimensions[] = $dimension[0] . "x" . $dimension[1];
            echo $thumb . "\n";
        }
    }
    closedir($handle);
    $result['json-files'] = json_encode($files);
    $result['json-dimensions'] = json_encode($dimensions);
    $result['count-pictures'] = $x > 0 ? $x : 0;
    return $result;
}
Example #17
0
 /** Build the image
  * 
  * @param string $image
  * @param string $party
  */
 public function buildImage($image, $party)
 {
     $party = str_replace(' ', '_', $party);
     list($w, $h, $type, $attr) = getimagesize('./' . $image);
     $string = '<img src="' . $image . '" alt="Party political logo" width="' . $w . '" height="' . $h . '" />';
     return $string;
 }
Example #18
0
 /** Returns an array. Element 0 - GD resource. Element 1 - width. Element 2 - height.
  * Returns FALSE on failure. The only one parameter $image can be an instance of this class,
  * a GD resource, an array(width, height) or path to image file.
  * @param mixed $image
  * @return array */
 protected function build_image($image)
 {
     if ($image instanceof gd) {
         $width = $image->get_width();
         $height = $image->get_height();
         $image = $image->get_image();
     } elseif (is_resource($image) && get_resource_type($image) == "gd") {
         $width = @imagesx($image);
         $height = @imagesy($image);
     } elseif (is_array($image)) {
         list($key, $width) = each($image);
         list($key, $height) = each($image);
         $image = imagecreatetruecolor($width, $height);
     } elseif (false !== (list($width, $height, $type) = @getimagesize($image))) {
         $image = $type == IMAGETYPE_GIF ? @imagecreatefromgif($image) : ($type == IMAGETYPE_WBMP ? @imagecreatefromwbmp($image) : ($type == IMAGETYPE_JPEG ? @imagecreatefromjpeg($image) : ($type == IMAGETYPE_JPEG2000 ? @imagecreatefromjpeg($image) : ($type == IMAGETYPE_PNG ? imagecreatefrompng($image) : ($type == IMAGETYPE_XBM ? @imagecreatefromxbm($image) : false)))));
         if ($type == IMAGETYPE_PNG) {
             imagealphablending($image, false);
         }
     }
     $return = is_resource($image) && get_resource_type($image) == "gd" && isset($width) && isset($height) && preg_match('/^[1-9][0-9]*$/', $width) !== false && preg_match('/^[1-9][0-9]*$/', $height) !== false ? array($image, $width, $height) : false;
     if ($return !== false && isset($type)) {
         $this->type = $type;
     }
     return $return;
 }
Example #19
0
 /**
  * Get Height: retorna a altura do arquivo
  * @param: i(int), indice do arquivo em parent::$files a ser pega a infomação
  * @access: public
  * @return: int
  */
 public function getHeight($i = 0)
 {
     if (!isset($this->files[$i]['height'])) {
         list($w, $this->files[$i]['height']) = getimagesize($this->files[$i]['url']);
     }
     return $this->files[$i]['height'];
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $mcid
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $mcid_id)
 {
     $this->validate($request, ['file' => 'required']);
     $mcid = MCID::findOrFail($mcid_id);
     $file = $_FILES['file'];
     $fileName = md5($mcid_id . $file['name'] . time());
     $path = str_finish($this->skin_path, '/') . $fileName;
     $content = File::get($file['tmp_name']);
     if (is_image($file['type']) && $file['size'] <= 150 * 1000) {
         list($img_w, $img_h) = getimagesize($file['tmp_name']);
         if ($img_w > 64 || $img_h > 64) {
             $error = "皮肤文件 '{$fileName}' 尺寸不正确.";
         } else {
             $result = $this->manager->saveFile($path, $content);
             if ($result === true) {
                 $skin = Skin::where('mcid_id', $mcid->id)->first();
                 if ($skin == null) {
                     $skin = new Skin();
                 }
                 $skin->mcid_id = $mcid->id;
                 $skin->url = $path;
                 $skin->save();
                 return redirect()->back()->withSuccess("皮肤文件 '{$fileName}' 上传成功.");
             } else {
                 $error = $result ?: "皮肤文件 '{$fileName}' 上传失败.";
             }
         }
     } else {
         $error = "皮肤文件 '{$fileName}' 格式或大小不正确.";
     }
     return redirect()->back()->withErrors([$error]);
 }
Example #21
0
function thumb($filename, $destination = null, $dst_w = null, $dst_h = null, $isReservedSource = false, $scale = 0.5)
{
    list($src_w, $src_h, $imagetype) = getimagesize($filename);
    if (is_null($dst_w) || is_null($dst_h)) {
        $dst_w = ceil($src_w * $scale);
        $dst_h = ceil($src_h * $scale);
    }
    $mime = image_type_to_mime_type($imagetype);
    $createFun = str_replace("/", "createfrom", $mime);
    $outFun = str_replace("/", null, $mime);
    $src_image = $createFun($filename);
    $dst_image = imagecreatetruecolor($dst_w, $dst_h);
    imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
    //image_50/sdfsdkfjkelwkerjle.jpg
    if ($destination && !file_exists(dirname($destination))) {
        mkdir(dirname($destination), 0777, true);
    }
    $dstFilename = $destination == null ? getUniName() . "." . getExt($filename) : $destination;
    $outFun($dst_image, $dstFilename);
    imagedestroy($src_image);
    imagedestroy($dst_image);
    if (!$isReservedSource) {
        unlink($filename);
    }
    return $dstFilename;
}
 /**
  * Loads image source and its properties to the instanciated object
  *
  * @param string $filename
  * @return ImageResize
  * @throws \Exception
  */
 public function __construct($filename)
 {
     $image_info = @getimagesize($filename);
     if (!$image_info) {
         throw new \Exception('Could not read file');
     }
     list($this->original_w, $this->original_h, $this->source_type) = $image_info;
     switch ($this->source_type) {
         case IMAGETYPE_GIF:
             $this->source_image = imagecreatefromgif($filename);
             break;
         case IMAGETYPE_JPEG:
             $this->source_image = $this->imageCreateJpegfromExif($filename);
             // set new width and height for image, maybe it has changed
             $this->original_w = ImageSX($this->source_image);
             $this->original_h = ImageSY($this->source_image);
             break;
         case IMAGETYPE_PNG:
             $this->source_image = imagecreatefrompng($filename);
             break;
         default:
             throw new \Exception('Unsupported image type');
             break;
     }
     return $this->resize($this->getSourceWidth(), $this->getSourceHeight());
 }
Example #23
0
function get_image($file)
{
    /*
    	Create a resource from image file and return it with getimagesize() array
    	$file - image file or resource
    	return array('res'=>$image_resource, 'imgsize'=>getimagesize($file))
    */
    if (is_file($file) === true && file_exists($file) === true && is_readable($file) === true) {
        $img_size = getimagesize($file);
        if ($img_size !== false) {
            $im_mime = $img_size['mime'];
            // Get the image from file
            if ($im_mime === 'image/jpeg') {
                $res = imagecreatefromjpeg($file);
            } else {
                if ($im_mime === 'image/gif') {
                    $res = imagecreatefromgif($file);
                } else {
                    if ($im_mime === 'image/png') {
                        $res = imagecreatefrompng($file);
                    } else {
                        // Exit if not supported format
                        return false;
                    }
                }
            }
            return array('res' => $res, 'imgsize' => $img_size);
        }
    }
    return false;
}
Example #24
0
 /**
  * Upload a profile image.
  * @return boolean True iff success.
  */
 function uploadProfileImage()
 {
     import('classes.file.PublicFileManager');
     $publicFileManager = new PublicFileManager();
     $user = $this->getUser();
     $type = $publicFileManager->getUploadedFileType('uploadedFile');
     $extension = $publicFileManager->getImageExtension($type);
     if (!$extension) {
         return false;
     }
     $uploadName = 'profileImage-' . (int) $user->getId() . $extension;
     if (!$publicFileManager->uploadSiteFile('uploadedFile', $uploadName)) {
         return false;
     }
     $filePath = $publicFileManager->getSiteFilesPath();
     list($width, $height) = getimagesize($filePath . '/' . $uploadName);
     if ($width > PROFILE_IMAGE_MAX_WIDTH || $height > PROFILE_IMAGE_MAX_HEIGHT || $width <= 0 || $height <= 0) {
         $userSetting = null;
         $user->updateSetting('profileImage', $userSetting);
         $publicFileManager->removeSiteFile($filePath);
         return false;
     }
     $user->updateSetting('profileImage', array('name' => $publicFileManager->getUploadedFileName('uploadedFile'), 'uploadName' => $uploadName, 'width' => $width, 'height' => $height, 'dateUploaded' => Core::getCurrentDate()));
     return true;
 }
Example #25
0
function getimages($dir)
{
    global $imagetypes;
    //		array to hold return values;
    $retval = array();
    //		add trailing slashes if missing;
    if (substr($dir, -1) != "/") {
        $dir .= "/images/";
    }
    //		Full server path to dir
    $fulldir = "{$_SERVER['DOCUMENT_ROOT']}/{$dir}";
    // $fulldir ="localhost/novademo-localhost/images/";
    $d = @dir($fulldir) or die("getimages: Failed opening directory {$_SERVER['DOCUMENT_ROOT']}/{$dir} for reading");
    while (false != ($entry = $d->read())) {
        //		skip hidden files
        if ($entry[0] == ".") {
            continue;
        }
        //		check for image files
        $f = escapeshellarg("{$fulldir}" . "{$entry}");
        $mimetype = trim(`file -bi {$f}`);
        foreach ($imagetypes as $valid_type) {
            if (preg_match("@^{$valid_type}@", $mimetype)) {
                $retval[] = array('file' => "/{$dir}" . "{$entry}", 'size' => getimagesize("{$fulldir}" . "{$entry}"));
                break;
            }
        }
    }
    $d->close();
    return $retval;
}
 public function loadFile($thumbnail, $image)
 {
     // try and use getimagesize()
     // on failure, use identify instead
     $imgData = @getimagesize($image);
     if (!$imgData) {
         exec($this->magickCommands['identify'] . ' ' . escapeshellarg($image), $stdout, $retval);
         if ($retval === 1) {
             throw new \Exception('Image could not be identified.');
         } else {
             // get image data via identify
             list($img, $type, $dimen) = explode(' ', $stdout[0]);
             list($width, $height) = explode('x', $dimen);
             $this->sourceWidth = $width;
             $this->sourceHeight = $height;
             $this->sourceMime = $this->mimeMap[strtolower($type)];
         }
     } else {
         // use image data from getimagesize()
         $this->sourceWidth = $imgData[0];
         $this->sourceHeight = $imgData[1];
         $this->sourceMime = $imgData['mime'];
     }
     $this->image = $image;
     // open file resource
     $source = fopen($image, 'r');
     $this->source = $source;
     $thumbnail->initThumb($this->sourceWidth, $this->sourceHeight, $this->maxWidth, $this->maxHeight, $this->scale, $this->inflate);
     return true;
 }
 public function check_img_size($file)
 {
     $mis_params = get_option('mis_img_params');
     // Check to see what kind of input the user is editing
     $meta_key = get_user_meta(get_current_user_id(), 'last_user_field_mod', true);
     // check if there is a custom field image restriction
     if (is_array($mis_params['custom_field']) && array_key_exists($meta_key['field_key'], $mis_params['custom_field'])) {
         $min_width = $mis_params['custom_field'][$meta_key['field_key']][0];
         $min_height = $mis_params['custom_field'][$meta_key['field_key']][1];
     } elseif ($meta_key['field_key'] === false) {
         $post_type = get_post_type($_REQUEST['post_id']);
         if (is_array($mis_params['post_type']) && array_key_exists($post_type, $mis_params['post_type'])) {
             $min_width = $mis_params['post_type'][$post_type][0];
             $min_height = $mis_params['post_type'][$post_type][1];
         }
     }
     if (isset($min_width) && isset($min_height)) {
         $img = getimagesize($file['tmp_name']);
         $minimum = array('width' => $min_width, 'height' => $min_height);
         $width = $img[0];
         $height = $img[1];
         if ($width < $minimum['width']) {
             return array("error" => "Image dimensions are too small. Minimum width is {$minimum['width']}px. Uploaded image width is {$width} px");
         } elseif ($height < $minimum['height']) {
             return array("error" => "Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image height is {$height} px");
         } else {
             return $file;
         }
     } else {
         return $file;
     }
 }
Example #28
-1
function bilderAnzeigen($eintragid)
{
    $ordnerid = $eintragid;
    $zaehler = 1;
    $directory = "attachments/{$eintragid}/fotos/";
    if (is_dir($directory) == true) {
        $handle = opendir($directory);
        while (false !== ($file = readdir($handle))) {
            $endung = substr($file, -4);
            if ($endung == ".GIF" || $endung == ".JPG" || $endung == ".gif" || $endung == ".jpg" || $endung == "jpeg" || $endung == ".png" || $endung == ".bmp") {
                $gezeigtesBild = "{$directory}{$file}";
                $bildGroesseErmitteln = getimagesize($gezeigtesBild);
                $bildBreite = $bildGroesseErmitteln[0] + 20;
                $bildHoehe = $bildGroesseErmitteln[1] + 20;
                $dateityp = "fotos";
                echo "<a href='#toFoto' onClick='window.open(\"{$gezeigtesBild}\",\"Bild\",\"width={$bildBreite},height={$bildHoehe},left=0,top=0,toolbar=no,status=no\");'><img src='{$gezeigtesBild}' height='80' border='1'></a>&nbsp;";
                if (isset($_SESSION["username"])) {
                    echo "<a href='#' onClick='loeschpop(\"{$file}\",\"{$ordnerid}\",\"{$dateityp}\");'><img src='picts/delete.gif' border='0' alt='loescht Bild'></a>&nbsp;&nbsp;&nbsp;";
                }
                if ($zaehler / 3 == 1) {
                    echo "<br>";
                    $zaehler = 1;
                } else {
                    $zaehler++;
                }
            }
            //end if
        }
        //end while
        closedir($handle);
    } else {
        echo "";
    }
    //end if
}
Example #29
-1
 public static function getAsJson($file, $force = false)
 {
     $json = array();
     getimagesize($file, $info);
     if (isset($info["APP13"])) {
         $iptc = iptcparse($info["APP13"]);
         if (isset($iptc['2#120'])) {
             $caption = implode('|', $iptc['2#120']);
             // nb: '|' should never actually appear
             $caption = ensureUTF8($caption);
             // since could be 'local' encoding
             $caption = mysql_escape_string($caption);
             // safety. stackoverflow.com/q/1162491
             $json['caption'] = $caption;
         }
         if (isset($iptc['2#025'])) {
             $json['keywords'] = $iptc['2#025'];
         }
         // keep as array
         set_error_handler("ignoreAnyError", E_ALL);
         // TOTEST, currently no exif enabled on localhost
         if (function_exists('exif_read_data')) {
             $json['exif'] = exif_read_data($tmpfile, 0, false);
         }
         // fails on a very few files (corrupt EXIF)
         restore_error_handler();
     }
     Log::info("json for :" . $file);
     Log::info($json);
     return $json;
 }
Example #30
-1
 function output()
 {
     $arr = $this->ret;
     $bg = DATA_DIR . '/cache/vcodebg.png';
     $image = imagecreatefrompng($bg);
     list($w, $baseH) = getimagesize($bg);
     header('Content-type: image/png');
     $x = 1;
     foreach ($arr as $i => $filename) {
         list($w, $h) = getimagesize($filename);
         $source = imagecreatefrompng($filename);
         $t_id = imagecolortransparent($source);
         $rotate = imagerotate($source, rand(-20, 20), $t_id);
         $w2 = $w * $baseH / $h;
         imagecopyresized($image, $rotate, $x, 0, 0, 0, $w2, $baseH, $w, $h);
         imagedestroy($source);
         imagedestroy($rotate);
         $x += $w2;
     }
     $x += 1;
     $dst = imagecreatetruecolor($x, $baseH);
     imagecopyresampled($dst, $image, 0, 0, 0, 0, $x, $baseH, $x, $baseH);
     imagepng($dst);
     imagedestroy($image);
     imagedestroy($dst);
     exit;
 }