/**
  * Upload the image, resize and store request in DB
  *
  * @param  \Illuminate\Http\Request  $request
  */
 public function upload(Request $request)
 {
     $validator = Validator::make($request->all(), ['image' => 'required|mimes:jpeg,bmp,png', 'width' => 'required', 'height' => 'required']);
     if ($validator->fails()) {
         return redirect('/')->withErrors($validator)->withInput();
     } else {
         $_image = $request->file('image');
         $_width = $request->input('width');
         $_height = $request->input('height');
         $extension = $_image->getClientOriginalExtension();
         $fileName = time() . '_' . md5(rand(0, 9999)) . '.' . $extension;
         if ($_image->isValid()) {
             // Uploading file to given path
             $_image->move($this->upload_path, $fileName);
             // Resize the uploaded image
             $image = new ImageResize($this->upload_path . '/' . $fileName);
             $image->resize($_width, $_height);
             $image->save($this->upload_path . '/' . $fileName);
             // Save the request info
             $model = new ImageModel();
             $model->filename = $_image->getClientOriginalName();
             $model->width = $_width;
             $model->height = $_height;
             $model->save();
             // Delete the uploaded file
             $file_contents = file_get_contents($this->upload_path . '/' . $fileName);
             File::delete($this->upload_path . '/' . $fileName);
             return response($file_contents)->header('Content-Type', 'image/jpg')->header('Content-Transfer-Encoding', 'Binary')->header('Content-disposition', 'attachment; filename="' . $_image->getClientOriginalName() . '"');
         } else {
             Session::flash('error', 'Something went wrong while uploading the image.');
             return redirect('/');
         }
     }
 }
Example #2
0
 /**
  * 修剪图片的大小
  * @param $originName
  * @param $targetName
  * @param $width
  * @param $height
  * @param bool $allow_enlarge 如果是true则可以将小于原始大小的图片放大
  */
 public static function resizeImage($originName, $targetName, $width, $height, $allow_enlarge = false, $quality = 100)
 {
     if (file_exists($originName)) {
         $image = new ImageResize($originName);
         $image->crop($width, $height, $allow_enlarge);
         $image->save($targetName, null, $quality);
     }
 }
Example #3
0
 protected function makeThumb($file, MediaProvider $media)
 {
     $name = 'thumb-' . $media->file;
     $new = $media->path . '/' . $name;
     $image = new ImageResize($file);
     $image->resizeToBestFit(150, 150);
     $image->save(storage_path() . $new);
     return $name;
 }
 private function uploadImage($file)
 {
     $destinationPath = public_path('img/wishes/');
     $filename = $this->makeImageNameUnique($file);
     $image = new ImageResize($file->getPathName());
     $image->resizeToBestFit(500, 500);
     $image->save($destinationPath . $filename, IMAGETYPE_JPEG);
     return $filename;
 }
Example #5
0
 public function generateThumbnail($name)
 {
     $image = new ImageResize(self::PATH_ORIGINALS . DIRECTORY_SEPARATOR . $name);
     $image->resizeToWidth(1900);
     unlink(self::PATH_ORIGINALS . DIRECTORY_SEPARATOR . $name);
     $image->save(self::PATH_ORIGINALS . DIRECTORY_SEPARATOR . $name);
     $image = new ImageResize(self::PATH_ORIGINALS . DIRECTORY_SEPARATOR . $name);
     $image->resizeToWidth(200);
     $image->save(self::PATH_THUMBNAILS . DIRECTORY_SEPARATOR . $name);
 }
Example #6
0
 /**
  * Resize an image and optionally rename it.
  *
  * @param string $path
  * @param string $filename
  * @param int $width
  * @param string|null $newFilename
  */
 public function resizeToWidth($path, $filename, $width, $newFilename = null)
 {
     $fullFilename = $path . '/' . $filename;
     $image = new ImageResize($fullFilename);
     $image->resizeToWidth($width, true);
     if (is_string($newFilename) && !empty($newFilename)) {
         $image->save($path . '/' . $newFilename);
         return;
     }
     $image->save($fullFilename);
 }
Example #7
0
 public function crop($images)
 {
     $this->makeRootDirectory();
     foreach ($images as $image) {
         foreach ($this->devices as $key => $value) {
             $img = new ImageResize($image);
             $img->crop($value[0], $value[1], false);
             $this->saveImage($img, $key, $image, $value[2]);
             unset($img);
         }
     }
     $directoryFullPath = "downloads/{$this->downloadDir}";
     $this->zipDirectory($directoryFullPath);
     $this->cleanUp($directoryFullPath);
     return $this->downloadDir;
 }
 public function postImage(Request $request)
 {
     $validator = Validator::make($request->all(), ['height' => 'integer', 'width' => 'integer', 'image_file' => 'required|image|mimes:png,jpg,jpeg,gif,bmp']);
     if ($validator->fails()) {
         return redirect('/')->withErrors($validator)->withInput();
     }
     // if pass validation
     $image_name = $request->file('image_file')->getClientOriginalName();
     $image_extension = $request->file('image_file')->getClientOriginalExtension();
     $image_new_name = md5(microtime(true));
     $temp_file = base_path() . '/public/images/upload/' . strtolower($image_new_name . '_temp.' . $image_extension);
     $request->file('image_file')->move(base_path() . '/public/images/upload/', strtolower($image_new_name . '_temp.' . $image_extension));
     $origin_size = getimagesize($temp_file);
     $origin_width = $origin_size[0];
     $origin_height = $origin_size[1];
     // resize
     $image_resize = new ImageResize($temp_file);
     if (trim($request->get('height')) != "") {
         $height = $request->get('height');
     } else {
         $height = 0;
     }
     if (trim($request->get('width')) != "") {
         $width = $request->get('width');
     } else {
         $width = 0;
     }
     if ($width > 0 && $height > 0) {
         $image_resize->resize($width, $height);
     } else {
         if ($width == 0 && $height > 0) {
             $image_resize->resizeToHeight($height);
         } else {
             if ($width > 0 && $height == 0) {
                 $image_resize->resizeToWidth($width);
             }
         }
     }
     $image_resize->save(base_path() . '/public/images/upload/' . $image_new_name . '.' . $image_extension);
     $image_location = '/images/upload/' . $image_new_name . '.' . $image_extension;
     File::delete($temp_file);
     $image_data = array('image_name' => $image_name, 'image_extension' => $image_extension, 'image_location' => $image_location, 'origin_height' => $origin_height, 'origin_width' => $origin_width, 'height' => $height, 'width' => $width);
     $this->image_gestion->saveImage($image_data);
     return redirect('/')->with('message', 'Successfully upload image!');
 }
Example #9
0
 public function uploadFile()
 {
     $this->filename = $this->file->baseName . '.' . $this->file->extension;
     $this->avatar = Yii::$app->security->generateRandomString() . '.' . $this->file->extension;
     $this->type = $this->file->type;
     if ($this->validate()) {
         $this->save(false);
         $filePath = Yii::$app->params['imagePath'] . $this->avatar;
         $image = new ImageResize($this->file->tempName);
         if ($image->getSourceWidth() > 1200) {
             $image->resizeToWidth(1200)->save($filePath);
         } else {
             $this->file->saveAs($filePath);
         }
         return true;
     }
     return false;
 }
 public function upload(Request $request)
 {
     $path = $request->path();
     $galleryName = str_replace("%20", " ", explode('/', $path));
     $input = Input::all();
     $rules = array('file' => 'image');
     $validation = Validator::make($input, $rules);
     if ($validation->fails()) {
         return Response::make($validation->errors->first(), 400);
     }
     $destinationPath = 'gallery/' . $galleryName[1];
     // upload path
     if (!file_exists("gallery/")) {
         mkdir("gallery/", 0700);
         if (!file_exists($destinationPath)) {
             mkdir($destinationPath, 0700);
         }
     }
     $extension = Input::file('file')->getClientOriginalExtension();
     // getting file extension
     $originalName = Input::file('file')->getClientOriginalName();
     $alt = substr($originalName, 0, strpos($originalName, "."));
     $fileName = rand(1111111, 9999999) . '.' . $extension;
     // renameing image
     $upload_success = Input::file('file')->move($destinationPath, $fileName);
     // uploading file to given path
     $pathAndFile = "/" . $destinationPath . "/" . $fileName;
     $thumbnailPath = "/" . $destinationPath . "/thumbs/" . $fileName;
     $thumbDir = $destinationPath . "/thumbs";
     if (!file_exists($thumbDir)) {
         mkdir($thumbDir, 0700);
     }
     $image = new ImageResize($destinationPath . "/" . $fileName);
     $image->scale(50);
     $image->save($destinationPath . "/thumbs/" . $fileName);
     $size = getimagesize(ltrim($pathAndFile, '/'));
     $lastPosition = DB::table('images')->where('category', $galleryName[1])->max('position');
     if ($lastPosition == null) {
         $lastPosition = 0;
     }
     $nextPosition = $lastPosition + 1;
     DB::table('images')->insert(['category' => $galleryName[1], 'path' => $pathAndFile, 'thumbnail' => $thumbnailPath, 'alt_tag' => $alt, 'width' => $size[0], 'height' => $size[1], 'main_gallery' => 0, 'position' => $nextPosition]);
 }
Example #11
0
/**
 * @param string              $repo
 * @param string              $file
 * @param int                 $width
 * @param bool                $archived
 * @param \Slim\Http\Response $response
 * @return mixed
 */
function thumb($repo, $file, $width, $archived, $response, $format)
{
    $md5 = md5($file);
    $file = $md5[0] . '/' . $md5[0] . $md5[1] . '/' . $file;
    $path = $repo . ($archived ? 'archive/' : '') . $file;
    if (is_readable($path)) {
        $path = realpath($path);
        $pathParts = pathinfo($path);
        if (strpos($pathParts['dirname'], $repo) === 0) {
            $cacheDir = $repo . 'thumb/' . ($archived ? 'archive/' : '') . $file;
            if (!is_dir($cacheDir)) {
                if (!mkdir($cacheDir, 0777, true)) {
                    return $response->withStatus(403);
                }
            }
            if ($format != 'jpg') {
                $cacheFile = $cacheDir . '/' . $width . 'px-' . $pathParts['basename'];
            } else {
                $cacheFile = $cacheDir . '/' . $width . 'px-' . $pathParts['filename'] . '.jpg';
            }
            if (!is_readable($cacheFile)) {
                $image = new ImageResize($path);
                if ($width > $image->getSourceWidth()) {
                    return $response->withRedirect('/images/' . $file);
                } else {
                    $image->resizeToWidth($width);
                    if ($format != 'jpg') {
                        $image->save($cacheFile);
                    } else {
                        $image->save($cacheFile, IMAGETYPE_JPEG);
                    }
                }
            }
            $finfo = finfo_open(FILEINFO_MIME_TYPE);
            $type = finfo_file($finfo, $cacheFile);
            $stream = new \GuzzleHttp\Psr7\LazyOpenStream($cacheFile, 'r');
            return $response->withHeader('Content-type', $type)->withBody($stream);
        }
    }
    return $response->withStatus(404);
}
Example #12
0
* User: Sundareswaran
* Date: 29-08-2015
* Time: 23:33
*/
<form action="check.php" method="post" enctype="multipart/form-data">
    <input type="file" name="image" size="50">
    <input type="submit" value="upload">
</form>
<?php 
use Eventviva\ImageResize;
if (isset($_FILES['image'])) {
    require 'requireds/ImageResize.php';
    move_uploaded_file($_FILES['image']['tmp_name'], 'image.png');
    $org_info = getimagesize("image.png");
    echo $org_info[3] . '<br><br>';
    $image = new ImageResize('image.png');
    echo "<img src=\"image.png\" alt=\"image\" /><br><br>";
    $image->scale(30);
    $image->save('imageb.png');
}
/*
$org_info = getimagesize("image.png");
echo $org_info[1].' is height<br><br>';
echo $org_info[0].' is width<br><br>';
$rsr_org = imagecreatefrompng("image.png");
$rsr_scl = imagescale($rsr_org, $org_info[0]*0.5, $org_info[1]*0.5,  IMG_BICUBIC_FIXED);
imagepng($rsr_scl, "imagebfb.png");
imagedestroy($rsr_org);
imagedestroy($rsr_scl);
*/
if (isset($_FILES['image'])) {
Example #13
0
 public function resize($pathname)
 {
     $imageresize = new ImageResize($pathname);
     $imageresize->resize($this->width, $this->height);
     $imageresize->save('imgs/' . $this->filename);
 }
function letsgo($h, $d)
{
    while (false !== ($file = readdir($h))) {
        if ($file != '.' && $file != '..' && $file != '.DS_Store') {
            if (is_dir($d . $file)) {
                echo "F {$file}\n";
                if ($hh = opendir($d . $file . "/")) {
                    letsgo($hh, $d . $file . "/");
                }
            }
            if (is_file($d . $file)) {
                // echo "f $file\n";
                if (true) {
                    $quality = 100;
                    echo filesize($d . $file) . "\n";
                    $image = new ImageResize($d . $file);
                    if (imagesx(imagecreatefromjpeg($d . $file)) > 300) {
                        $image->scale(50);
                        $quality = 75;
                    }
                    $image->quality_jpg = $quality;
                    if (!file_exists($d . str_replace(".jpg", "s.jpg", $file))) {
                        if (!file_exists($d . str_replace(".jpg", "ss.jpg", $file))) {
                            $image->save($d . str_replace(".jpg", "s.jpg", $file));
                            echo "{$file}\n";
                        }
                    }
                    // $img = imagecreatefromjpeg($d.$file);
                    // $out = imagejpeg($img,null,50);
                    // file_put_contents($d.str_replace(".jpg","s.jpg",$file), imagejpeg($img,null,50));
                }
            }
        }
    }
    closedir($h);
}
Example #15
0
 /**
  * @param  string $file
  * @param  int $width
  * @param  int $height
  * @return void
  */
 public function resizeAndSave($file, $width, $height)
 {
     $image = new ImageResize($_SERVER['DOCUMENT_ROOT'] . $file);
     if ($width == 'auto') {
         $image->resizeToHeight($height);
     } elseif ($height == 'auto') {
         $image->resizeToWidth($width);
     } else {
         $image->crop($width, $height);
     }
     unlink($_SERVER['DOCUMENT_ROOT'] . $file);
     $image->save($_SERVER['DOCUMENT_ROOT'] . $file);
 }
Example #16
0
 public function testOutputPng()
 {
     $image = $this->createImage(200, 100, 'png');
     $resize = new ImageResize($image);
     ob_start();
     // supressing header errors
     @$resize->output();
     $image_contents = ob_get_clean();
     $info = finfo_open();
     $type = finfo_buffer($info, $image_contents, FILEINFO_MIME_TYPE);
     $this->assertEquals('image/png', $type);
 }
Example #17
0
 public function editarImagem($id = FALSE, $docente = FALSE)
 {
     if ($this->filtraInt($id)) {
         $diretorio = "upload/";
         move_uploaded_file($_FILES['imagem']["tmp_name"], $diretorio . $_FILES['imagem']["name"]);
         $resize = new ImageResize($diretorio . $_FILES['imagem']["name"]);
         $resize->crop(240, 320);
         unlink($diretorio . $_FILES['imagem']["name"]);
         $resize->save($diretorio . $_FILES['imagem']["name"]);
         $this->pessoa->setImagem($diretorio . $_FILES['imagem']["name"]);
         $this->pessoa->setId($id);
         $p = $this->pessoa->editar($this->pessoa);
         if ($p) {
             $this->redirecionar("docente/informacao/" . $docente);
         }
     }
     $this->redirecionar("docente");
 }
Example #18
0
<?php

include '../config.php';
$result = array('suc' => false, 'msg' => 'خطا :: حاول مرة اخرى', 'idMsg' => 3);
if (!trim($_POST['NameDevices'])) {
    $result['msg'] = 'قم باضافة نوع الجهاز';
    echo json_encode($result);
    exit;
}
include '../Class/ImageResize.php';
$ImgDir = IMAGEDEVICES . $_POST['ImageUrl'];
$ext = pathinfo($ImgDir, PATHINFO_EXTENSION);
$time = time() . '.' . $ext;
use Eventviva\ImageResize;
$image = new ImageResize($ImgDir);
$image->resizeToBestFit(300, 300);
$image->save(IMAGEDEVICES . $time);
$Mdata = array('NameDevices' => $db->escape($_POST['NameDevices']), 'ImageUrl' => $time);
//$db->where('ID', $_GET['ID']);
$infoList = $db->insert('typeDevices', $Mdata);
if ($db->count > 0) {
    $result = array('suc' => true, 'msg' => 'تمت العملية بنجاح', 'idMsg' => 1);
}
echo json_encode($result);
Example #19
0
 public function editarImagem($id)
 {
     if ($this->filtraInt($id)) {
         $diretorio = "upload/";
         move_uploaded_file($_FILES['imagem']["tmp_name"], $diretorio . $_FILES['imagem']["name"]);
         $resize = new ImageResize($diretorio . $_FILES['imagem']["name"]);
         $resize->crop(240, 320);
         unlink($diretorio . $_FILES['imagem']["name"]);
         $resize->save($diretorio . $_FILES['imagem']["name"]);
         $this->pessoa->setImagem($diretorio . $_FILES['imagem']["name"]);
         $this->pessoa->setId($id);
         $p = $this->pessoa->editar($this->pessoa);
         if ($p) {
             $this->redirecionar("matricula");
         }
     }
     $this->redirecionar("dashboard");
 }
 /**
  * Returns a resized image url.
  * Resized on height constraint.
  *
  * @param string $url    Base url.
  * @param int    $height Height to resize to.
  *
  * @return string
  */
 public static function height($url, $height = 0)
 {
     if (empty($height) || !is_numeric($height)) {
         $height = get_option('thumbnail_size_h');
     }
     $info = pathinfo($url);
     $cacheKey = preg_replace(['/:filename/', '/:width/', '/:height/'], [$info['filename'], '', $height], get_option('thumbnail_cache_format', ':filename_:widthx:height'));
     return Cache::remember($cacheKey, get_option('thumbnail_cache_minutes', 43200), function () use($url, $height, $info) {
         $upload_dir = wp_upload_dir();
         $size = getimagesize($url);
         $assetPath = sprintf('/%s_x%s.%s', $info['filename'], $height, $info['extension']);
         if (!file_exists($upload_dir['path'] . $assetPath)) {
             $image = new ImageResize($url);
             $image->interlace = 1;
             $image->scale(ceil(100 + ($height - $size[1]) / $size[1] * 100));
             $image->save($upload_dir['path'] . $assetPath);
         }
         return $upload_dir['url'] . $assetPath;
     });
 }
Example #21
0
<?php

ini_set('memory_limit', '1024M');
set_time_limit(0);
include 'libs/php-image-resize/src/ImageResize.php';
use Eventviva\ImageResize;
$path = "img/ivymod";
$files = scandir($path);
$cont = 0;
foreach ($files as $value) {
    if (!is_dir($value)) {
        echo $value . " **** ";
        $image = new ImageResize($path . '/' . $value);
        $image->resizeToWidth(840);
        $image->save('img/ivymod-840x1110/' . $value);
        echo "<a href='http://localhost/" . basename(__DIR__) . "/" . $path . "/840x1110" . $value . "' target='_blank' >" . $value . "</a><br/>";
        //echo "$path/840x1110/$value <br>";
        $cont++;
        //exit;
    }
}
echo "<br>Total: <b>" . $cont . "</b>";
 /**
  * Returns a resized image url.
  * Resized on height constraint.
  *
  * @param string $url    Base url.
  * @param int    $height Height to resize to.
  *
  * @return string
  */
 public static function height($url, $height = 0)
 {
     if (empty($height) || !is_numeric($height)) {
         $height = config('image.thumbs_height');
     }
     $info = pathinfo($url);
     $cacheKey = preg_replace(['/:filename/', '/:width/', '/:height/'], [$info['filename'], '', $height], config('image.cache_key_format'));
     return Cache::remember($cacheKey, config('image.cache_minutes'), function () use($url, $height, $info) {
         $size = getimagesize($url);
         $assetPath = sprintf('%s%s_x%s.%s', Config::get('image.thumbs_folder'), $info['filename'], $height, $info['extension']);
         if (!file_exists(public_path() . $assetPath)) {
             $image = new ImageResize($url);
             $image->interlace = 1;
             $image->scale(ceil(100 + ($height - $size[1]) / $size[1] * 100));
             $image->save(public_path() . $assetPath);
         }
         return URL::asset($assetPath);
     });
 }
Example #23
0
<?php

include "ImageResize.php";
use Eventviva\ImageResize;
$url = $_POST['img'];
$image = new ImageResize($url);
$image->resizeToWidth(500, 500);
$path_dissect = pathinfo($url);
$dis = strtok($path_dissect['basename'], '?');
$img = 'dp/' . $dis;
$image->save($img);
//file_put_contents($img, file_get_contents($url));
//echo "http://cryptlife.com/prayforchennai/".$img;
/*$png = imagecreatefromjpeg($img);
    $jpeg = imagecreatefrompng('overlay.png');
	list($width, $height) = getimagesize('overlay.png');
	list($newwidth, $newheight) = getimagesize($img);
	$out = imagecreatetruecolor("500", "500");
	imagecopyresampled($out, $jpeg, 0, 0, 0, 0, "500", "500", $width, $height);
	imagecopyresampled($out, $png, 0, 0, 0, 0, "500", "500", $newwidth, $newheight);
	imagejpeg($out, 'final/'.$dis, 100);*/
/*$png = imagecreatefrompng('overlay.png');
	$jpeg = imagecreatefromjpeg($img);

	list($width, $height) = getimagesize('overlay.png');
	list($newwidth, $newheight) = getimagesize($img);
	$out = imagecreatetruecolor($newwidth, $newheight);
	imagecopyresampled($out, $jpeg, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
	imagecopyresampled($out, $png, 0, 0, 0, 0, $newwidth, $newheight, $newwidth, $newheight);
	imagejpeg($out, 'final/'.$dis, 100);*/
$width = 500;
Example #24
0
function imageProcessingEngine($a_width, $a_height, $a_count, $a_files, $a_name, $a_crop_pos)
{
    //Crop Images
    for ($i = 0; $i < $a_count; $i++) {
        echo "<hr>";
        echo "<b>" . ($i + 1) . "." . "Image Taken for Processing...</b>";
        echo "<br>" . $a_files[$i];
        echo "<br>Preparing images for resizing...";
        echo "<br>Under Processing...";
        $image = new ImageResize($a_files[$i]);
        $image->crop($a_width, $a_height, false, $a_crop_pos);
        $image->save($a_files[$i]);
        echo "<br>" . $a_files[$i];
        echo "<br>Image resized Successfully...";
    }
    echo "<hr><b>All image files are resized successfully</b><br>";
}