本文整理汇总了PHP中SimpleImage类的典型用法代码示例。如果您正苦于以下问题:PHP SimpleImage类的具体用法?PHP SimpleImage怎么用?PHP SimpleImage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: imageDualResize
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}\"";
}
示例2: upload_imagem_unica
function upload_imagem_unica($pasta_upload, $novo_tamanho_imagem, $novo_tamanho_imagem_miniatura, $host_retorno, $upload_miniatura)
{
// data atual
$data_atual = data_atual();
// array com fotos
$fotos = $_FILES['foto'];
// extensoes de imagens disponiveis
$extensoes_disponiveis[] = ".jpeg";
$extensoes_disponiveis[] = ".jpg";
$extensoes_disponiveis[] = ".png";
$extensoes_disponiveis[] = ".gif";
$extensoes_disponiveis[] = ".bmp";
// nome imagem
$nome_imagem = $fotos['tmp_name'];
$nome_imagem_real = $fotos['name'];
// dimensoes da imagem
$image_info = getimagesize($_FILES["foto"]["tmp_name"]);
$largura_imagem = $image_info[0];
$altura_imagem = $image_info[1];
// extencao
$extensao_imagem = "." . strtolower(pathinfo($nome_imagem_real, PATHINFO_EXTENSION));
// nome final de imagem
$nome_imagem_final = md5($nome_imagem_real . $data_atual) . $extensao_imagem;
$nome_imagem_final_miniatura = md5($nome_imagem_real . $data_atual . $data_atual) . $extensao_imagem;
// endereco final de imagem
$endereco_final_salvar_imagem = $pasta_upload . $nome_imagem_final;
$endereco_final_salvar_imagem_miniatura = $pasta_upload . $nome_imagem_final_miniatura;
// informa se a extensao de imagem e permitida
$extensao_permitida = retorne_elemento_array_existe($extensoes_disponiveis, $extensao_imagem);
// se nome for valido entao faz upload
if ($nome_imagem != null and $nome_imagem_real != null and $extensao_permitida == true) {
// upload de imagem normal
$image = new SimpleImage();
$image->load($nome_imagem);
// aplica escala
if ($largura_imagem > $novo_tamanho_imagem) {
$image->resizeToWidth($novo_tamanho_imagem);
}
// salva a imagem grande
$image->save($endereco_final_salvar_imagem);
// upload de miniatura
if ($upload_miniatura == true) {
$image = new SimpleImage();
$image->load($nome_imagem);
// modo de redimencionar
if ($largura_imagem > $novo_tamanho_imagem_miniatura) {
$image->resizeToWidth($novo_tamanho_imagem_miniatura);
}
// salva a imagem em miniatura
$image->save($endereco_final_salvar_imagem_miniatura);
}
// array de retorno
$retorno['normal'] = $host_retorno . $nome_imagem_final;
$retorno['miniatura'] = $host_retorno . $nome_imagem_final_miniatura;
$retorno['normal_root'] = $endereco_final_salvar_imagem;
$retorno['miniatura_root'] = $endereco_final_salvar_imagem_miniatura;
// retorno
return $retorno;
}
}
示例3: actionUpload
/**
* 上传图片
*/
public function actionUpload()
{
$fn = $_GET['CKEditorFuncNum'];
$url = WaveCommon::getCompleteUrl();
$imgTypeArr = WaveCommon::getImageTypes();
if (!in_array($_FILES['upload']['type'], $imgTypeArr)) {
echo '<script type="text/javascript">
window.parent.CKEDITOR.tools.callFunction("' . $fn . '","","图片格式错误!");
</script>';
} else {
$projectPath = Wave::app()->projectPath;
$uploadPath = $projectPath . 'data/uploadfile/substance';
if (!is_dir($uploadPath)) {
mkdir($uploadPath, 0777);
}
$ym = WaveCommon::getYearMonth();
$uploadPath .= '/' . $ym;
if (!is_dir($uploadPath)) {
mkdir($uploadPath, 0777);
}
$imgType = strtolower(substr(strrchr($_FILES['upload']['name'], '.'), 1));
$imageName = time() . '_' . rand() . '.' . $imgType;
$file_abso = $url . '/data/uploadfile/substance/' . $ym . '/' . $imageName;
$SimpleImage = new SimpleImage();
$SimpleImage->load($_FILES['upload']['tmp_name']);
$SimpleImage->resizeToWidth(800);
$SimpleImage->save($uploadPath . '/' . $imageName);
echo '<script type="text/javascript">
window.parent.CKEDITOR.tools.callFunction("' . $fn . '","' . $file_abso . '","上传成功");
</script>';
}
}
示例4: uploadFile
protected function uploadFile()
{
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $this->path)) {
$path = $this->path;
if (!$this->db->query("INSERT photo (name,folder,time,status) \n\t\t\tVALUES ('" . $this->name . "','" . $this->folder . "','" . time() . "','temp')")) {
die("error");
}
$id = $this->db->getLastId();
$this->image->load($path);
$full = new SimpleImage();
$full->load($path);
if ($full->getWidth() > 1200) {
$full->resizeToWidth(1200);
}
$full->save(str_replace('.', '.full.', $path));
if ($this->image->getWidth() > 600) {
$this->image->resizeToWidth(600);
}
$this->image->save($path);
$size = $this->f->getFullSize($path, 90, 90);
$img = array('name' => $this->name, 'path' => $path, 'count' => $this->getNum(), 'width' => $size['width'], 'height' => $size['height'], 'id' => $id);
echo json_encode($img);
} else {
echo "error";
}
}
示例5: processScreenshots
function processScreenshots($gameID)
{
## Select all fanart rows for the requested game id
$ssResult = mysql_query(" SELECT filename FROM banners WHERE keyvalue = {$gameID} AND keytype = 'screenshot' ORDER BY filename ASC ");
## Process each fanart row incrementally
while ($ssRow = mysql_fetch_assoc($ssResult)) {
## Construct file names
$ssOriginal = $ssRow['filename'];
$ssThumb = "screenshots/thumb" . str_replace("screenshots", "", $ssRow['filename']);
## Check to see if the original fanart file actually exists before attempting to process
if (file_exists("../banners/{$ssOriginal}")) {
## Check if thumb already exists
if (!file_exists("../banners/{$ssThumb}")) {
## If thumb is non-existant then create it
$image = new SimpleImage();
$image->load("../banners/{$ssOriginal}");
$image->resizeToWidth(300);
$image->save("../banners/{$ssThumb}");
//makeFanartThumb("../banners/$ssOriginal", "../banners/$ssThumb");
}
## Get Fanart Image Dimensions
list($image_width, $image_height, $image_type, $image_attr) = getimagesize("../banners/{$ssOriginal}");
$ssWidth = $image_width;
$ssHeight = $image_height;
## Output Fanart XML Branch
print "<screenshot>\n";
print "<original width=\"{$ssWidth}\" height=\"{$ssHeight}\">{$ssOriginal}</original>\n";
print "<thumb>{$ssThumb}</thumb>\n";
print "</screenshot>\n";
}
}
}
示例6: _generateThumbnail
/**
* Generates the thumbnail for a given file.
*/
protected function _generateThumbnail()
{
$image = new SimpleImage();
$image->load($this->source);
$image->resizeToWidth(Configure::read('Image.width'));
$image->save($this->thumb_path);
}
示例7: insertImageSub
function insertImageSub($file, $sub_id, $menu_id)
{
$error = false;
$arr = explode('.', $file["name"]);
$imageFileType = end($arr);
if ($file["size"] > 5000000) {
$error = true;
}
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
$error = true;
}
if (!$error) {
$target_dir = "../images/menu_" . $menu_id . "/sub_" . $sub_id . "/";
$target_file = $target_dir . $file["name"];
//
if (!file_exists($target_dir)) {
mkdir($target_dir, 0777, true);
}
if (file_exists($target_file)) {
unlink($target_file);
}
if (move_uploaded_file($file["tmp_name"], $target_file)) {
include 'classSimpleImage.php';
$image = new SimpleImage();
$image->load($target_file);
$image->resize(218, 138);
$image->save($target_file);
$arr = explode("../", $target_file);
return end($arr);
}
} else {
return false;
}
}
示例8: action_index
public function action_index()
{
$tags = array();
$imager = new SimpleImage();
if ($this->request->param('path')) {
// Берем новость
$post = ORM::factory('blog')->where('url', '=', $this->request->param('path'))->find();
} else {
$post = ORM::factory('blog');
}
if ($_POST) {
$post_name = Arr::get($_POST, 'post_name');
$post_url = Arr::get($_POST, 'post_url');
$short_text = Arr::get($_POST, 'short_text');
$full_text = Arr::get($_POST, 'full_text');
$tag = Arr::get($_POST, 'tag');
// Загрузка изображения
$image = $_FILES["imgupload"]["name"];
if (!empty($image)) {
$imager = new SimpleImage();
//$this->news->deleteImage($post->id);
//$image = $this->image->upload_image($image['tmp_name'], $image['name'], $this->config->news_images_dir."big/");
move_uploaded_file($_FILES["imgupload"]["tmp_name"], "files/blog/" . $_FILES["imgupload"]["name"]);
$imager->load("files/blog/" . $image);
$imager->resize(200, 200);
$imager->save("files/blog/miniatures/" . $image);
}
$post->set('name', $post_name)->set('url', $post_url)->set('date', DB::expr('now()'))->set('short_text', $short_text)->set('full_text', $full_text)->set('image', $image)->set('tag_id', ORM::factory('tags')->where('name', '=', $tag)->find())->save();
}
$tags = ORM::factory('tags')->find_all();
$content = View::factory('/admin/post')->bind('tags', $tags)->bind('post', $post);
$this->template->content = $content;
}
示例9: ImageResize
function ImageResize($file)
{
$image = new SimpleImage();
$image->load('traffic-images/temp/' . $file);
$image->resize(300, 200);
$image->save('traffic-images/' . $file);
unlink("traffic-images/temp/" . $file);
}
示例10: Load
public function Load($pathToImage)
{
if (!extension_loaded('gd')) {
die('gd extension is required for image upload');
}
$image = new SimpleImage();
$image->load($pathToImage);
return new Image($image);
}
示例11: saveImageInFile
public function saveImageInFile($file)
{
$t = $file['tmp_name'];
$n = $file['name'];
$path = App::get("uploads_dir_original") . DIRECTORY_SEPARATOR . $n;
move_uploaded_file($t, $path);
$image = new SimpleImage();
$image->load($path);
$image->resize(250, 250);
$image->save(App::get("uploads_dir_small") . DIRECTORY_SEPARATOR . $n);
return $n;
}
示例12: upload
function upload()
{
if (!isset($_FILES['upload'])) {
$this->directrender('S3/S3');
return;
}
global $params;
// Params to vars
$client_id = '1b5cc674ae2f335';
// Validations
$this->startValidations();
$this->validate($_FILES['upload']['error'] === 0, $err, 'upload error');
$this->validate($_FILES['upload']['size'] <= 10 * 1024 * 1024, $err, 'size too large');
// Code
if ($this->isValid()) {
$fname = $_FILES['upload']['tmp_name'];
require_once $GLOBALS['dirpre'] . 'includes/S3/SimpleImage.php';
$image = new SimpleImage();
$this->validate($image->load($fname), $err, 'invalid image type');
if ($this->isValid()) {
if ($image->getHeight() > 1000) {
$image->resizeToHeight(1000);
}
$image->save($fname);
function getMIME($fname)
{
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $fname);
finfo_close($finfo);
return $mime;
}
$filetype = explode('/', getMIME($fname));
$valid_formats = array("jpg", "png", "gif", "jpeg");
$this->validate($filetype[0] === 'image' and in_array($filetype[1], $valid_formats), $err, 'invalid image type');
if ($this->isValid()) {
require_once $GLOBALS['dirpre'] . 'includes/S3/s3_config.php';
//Rename image name.
$actual_image_name = time() . "." . $filetype[1];
$this->validate($s3->putObjectFile($fname, $bucket, $actual_image_name, S3::ACL_PUBLIC_READ), $err, 'upload failed');
if ($this->isValid()) {
$reply = "https://{$bucket}.s3.amazonaws.com/{$actual_image_name}";
$this->success('image successfully uploaded');
$this->directrender('S3/S3', array('reply' => "up(\"{$reply}\");"));
return;
}
}
}
}
$this->error($err);
$this->directrender('S3/S3');
}
示例13: uploadArquivo
function uploadArquivo($campoFormulario, $idGravado) {
$ext = pathinfo($_FILES[$campoFormulario][name], PATHINFO_EXTENSION);
if (($_FILES[$campoFormulario][name] <> "") && ($_FILES[$campoFormulario][size]) > 0 && in_array(strtolower($ext), $this->extensions)) {
$arquivoTmp = $_FILES[$campoFormulario]['tmp_name'];
$nome = str_replace(".", "", microtime(true)) . "_" . $_FILES[$campoFormulario]['name'];
if (function_exists("exif_imagetype")) {
$test = exif_imagetype($arquivoTmp);
$image_type = $test;
} else {
$test = getimagesize($arquivoTmp);
$image_type = $test[2];
}
if (in_array($image_type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP))) {
$image = new SimpleImage();
$image->load($arquivoTmp);
$l = $image->getWidth();
$h = $image->getHeight();
if ($l > $h) {
$funcao = "resizeToWidth";
$novoTamanho = 1024;
} else {
$funcao = "resizeToHeight";
$novoTamanho = 768;
}
$image->$funcao($novoTamanho);
$copiou = $image->save($this->diretorio . $nome);
if ($this->prefixoMarcaDagua) {
$image->$funcao(300);
$image->watermark();
$image->save($this->diretorio . $this->prefixoMarcaDagua . $nome);
}
if ($this->prefixoMiniatura) {
$image->load($arquivoTmp);
$image->$funcao(380);
$image->save($this->diretorio . $this->prefixoMiniatura . $nome);
}
} else {
$copiou = copy($arquivoTmp, $this->diretorio . $nome);
}
if ($copiou) {
$sql = "update $this->tabela set $this->campoBD = '$nome' where id='$idGravado'";
#$altualizaNome = mysql_query($sql) or die($sql . mysql_error);
$this->conexao->executeQuery($sql);
}
} else {
return false;
}
return $idGravado;
}
示例14: xulyImage
function xulyImage($img, $urlImgTemp, $urlImg, $urlImgThumb, $original = 1)
{
$file = $urlImgTemp . $img;
$sizeInfo = getimagesize($file);
if (is_array($sizeInfo)) {
include_once 'libraries/SimpleImage.php';
$image = new SimpleImage();
$image->load($file);
$width = $sizeInfo[0];
$height = $sizeInfo[1];
if ($width <= IMAGE_THUMB_WIDTH && $height <= IMAGE_THUMB_HEIGHT) {
copy($file, $urlImgThumb . $img);
} elseif ($width >= $height) {
$image->resizeToWidth(IMAGE_THUMB_WIDTH);
$image->save($urlImgThumb . $img);
} elseif ($width < $height) {
$image->resizeToHeight(IMAGE_THUMB_HEIGHT);
$image->save($urlImgThumb . $img);
}
if ($original == 1) {
$image->load($file);
if ($width >= $height && $width > IMAGE_MAX_WIDTH) {
$image->resizeToWidth(IMAGE_MAX_WIDTH);
$image->save($urlImg . $img);
} elseif ($width <= $height && $height > IMAGE_MAX_HEIGHT) {
$image->resizeToHeight(IMAGE_MAX_HEIGHT);
$image->save($urlImg . $img);
} else {
copy($file, $urlImg . $img);
}
if (file_exists($file)) {
unlink($file);
}
} else {
if (copy($file, $urlImg . $img)) {
if (file_exists($file)) {
unlink($file);
}
}
}
return true;
} else {
return false;
}
}
示例15: resizeImagesInFolder
function resizeImagesInFolder($dir, $i)
{
if (!is_dir('cover/' . $dir)) {
toFolder('cover/' . $dir);
}
$files = scandir($dir);
foreach ($files as $key => $file) {
if ($file != '.' && $file != '..') {
if (!is_dir($dir . '/' . $file)) {
echo $dir . '/' . $file;
$image = new SimpleImage();
$image->load($dir . '/' . $file);
if ($image->getHeight() < $image->getWidth()) {
$image->resizeToWidth(1920);
} else {
$image->resizeToHeight(1920);
}
// $new = 'cover/' . $dir . '/'.$image->name;
if ($i < 10) {
$new = 'cover/' . $dir . '/00' . $i . '.' . $image->type;
} elseif ($i < 100) {
$new = 'cover/' . $dir . '/0' . $i . '.' . $image->type;
} else {
$new = 'cover/' . $dir . '/' . $i . '.' . $image->type;
}
$image->save($new);
echo ' ---------> ' . $new . '<br>';
$i++;
} else {
resizeImagesInFolder($dir . '/' . $file, 1);
}
}
}
}