scale() public method

Resizes image according to given scale (proportionally)
public scale ( integer | float $scale ) : static
$scale integer | float
return static
Ejemplo n.º 1
0
 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]);
 }
Ejemplo n.º 2
0
* 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'])) {
    $scl_info = getimagesize("imagebfb.png");
    echo $scl_info[3];
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
 public function testScale()
 {
     $image = $this->createImage(200, 100, 'png');
     $resize = new ImageResize($image);
     $resize->scale(50);
     $this->assertEquals(100, $resize->getDestWidth());
     $this->assertEquals(50, $resize->getDestHeight());
 }
Ejemplo n.º 5
0
 /**
  * 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);
     });
 }
 /**
  * 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;
     });
 }