Giter VIP home page Giter VIP logo

yii2-image's Introduction

yii2-image

Simple to use Yii2 Framework extension for image manipulating using powerful Kohana Image Library. Inspired by old yii extension http://www.yiiframework.com/extension/image/ and Kohana Image Library https://github.com/kohana/image

Installation

Install as a composer package

Use this method to get continuous updates.

composer require yurkinx/yii2-image

or include the dependency in the composer.json file:

{
    "require": {
        "yurkinx/yii2-image": "^1.2"
       
    }
}

Configuration

In config file

/config/web.php

Add image component

'components' => array(
        ...
        'image' => array(
        	 	'class' => 'yii\image\ImageDriver',
        		'driver' => 'GD',  //GD or Imagick
        		),
		    )

Usage

$file=Yii::getAlias('@app/pass/to/file'); 
$image=Yii::$app->image->load($file);
header("Content-Type: image/png");
echo 	$image->resize($width,$height)->rotate(30)->render();

Supported methods out of the box from Kohana Image Library:

$image->resize($width = NULL, $height = NULL, $master = NULL);
$image->crop($width, $height, $offset_x = NULL, $offset_y = NULL);
$image->sharpen($amount);
$image->rotate($degrees);
$image->save($file = NULL, $quality = 100);
$image->render($type = NULL, $quality = 100);
$image->reflection($height = NULL, $opacity = 100, $fade_in = FALSE);
$image->flip($direction);
$image->background($color, $opacity = 100);
$image->watermark(Image $watermark, $offset_x = NULL, $offset_y = NULL, $opacity = 100);

Using resize with resize constrains

$image->resize($width, $height, \yii\image\drivers\Image::HEIGHT);
$image->resize($width, $height, \yii\image\drivers\Image::ADAPT)->background('#fff');

Using resize with resize constrains and best quality output image [for Imagick driver only]

Use 1 for best speed and lower quality, 100 for best quality and lower speed. Only values 1,100 currently supported

$image->resize($width, NULL, \yii\image\drivers\Image::WIDTH, 100);

Possible resize constrains:

// Resizing constraints ($master)
    const NONE    = 0x01;
    const WIDTH   = 0x02;
    const HEIGHT  = 0x03;
    const AUTO    = 0x04;
    const INVERSE = 0x05;
    const PRECISE = 0x06;
    const ADAPT   = 0x07;
    const CROP    = 0x08;

Using flip with flipping directions

// Flipping directions ($direction)
$image->flip(\yii\image\drivers\Image::HORIZONTAL);

Possible flipping directions:

     const HORIZONTAL = 0x11;
     const VERTICAL   = 0x12;

yii2-image's People

Contributors

coderfly avatar fschindler avatar mervick avatar pfarrer avatar yurkinx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-image's Issues

Resize pixelates images

Hi
I used the Image extension in Yii1.x extensively, so I'm not a stranger to manipulating images.

I've juts implemented your version and it's works great until I try and resize an image.

I've tried different combinations but my objective is to resize images to a thumbnail to fit into a 300px square, thus using the AUTO option. My line of code is:

$image->resize($size, $size, Yii\image\drivers\Image::AUTO);

The final image is massively pixelated (see https://www.dropbox.com/s/euviteiwk4v3izs/15e3420d3883067219be482ded44b35c.jpg)

Any ideas?

Multiple resize

How can I resize an image to multiple sizes?
E.g. A cropped image 300x300 and a resized image 1000x5000

Release

Could you tag a release version?

use \Imagick in drivers/Kohana/Image/Imagick.php

PHP Fatal error: Class 'yii\image\drivers\Imagick' not found in /var/www/..../webapp/vendor/yurkinx/yii2-image/yii/image/drivers/Kohana/Image/Imagick.php on line 54
PHP Fatal Error 'yii\base\ErrorException' with message 'Class 'yii\image\drivers\Imagick' not found'

New release 1.2??

Hi Yuri,

just wanted to ask if you could release a new version 1.1.2 or something of yurkinx/yii2-image to packagist so that (at least) I can use the fix for colorspaces in production.

Thanks in advance,
Matthias

Colorspace handling in Imagick

I'm trying to scale a JPEG image with CMYK colorspace. This resulted in an inverted image. I traced the problem back to the Kohana_Image_Imagick class. I know this is an 'external' library, but do we need to be compatible with the upstream version? Or is the current version hardcoded because it's already modified for this project?

About the bug itself: the class does this in a few occasions:

$image->setColorspace($this->im->getColorspace());

AFAIK, this does nothing. According to the PHP manual, these methods get and set the global colorspace of the library. This always returns 0 in my setup. The methods setImageColorspace and getImageColorspace return info local to the image object.

Also, the _do_adapt method doesn't handle colorspaces at all. This is the main problem in my setup, because it results in inverted images.

I see two possibilities:

  • Change and add the setColorspace/getColorspace calls to the setImage/getImage variants. This will result in images with the same colorspace as the original.
  • Always transform the colorspace to RGB at the start of the class and use it as default colorspace. This will result in RGB images.

I believe the GD library always returns RGB, but I can't find 100% proof of this. If this is the case, it would be better to use option 2, so both backends do the same thing.

In PHP 8.0 : \GDImage object is used instead of resource type

I noticed "image load + resize + save" would no longer work after upgrade to PHP 8.
I tracked down the issue as is_resource( $self->_image ) always returning false in function _load_image.
Since that function is called before all operations, it loads the original image again before saving it.

Here is an explanation.

So we need another test for $self->_image.
P.

Get EXIF

Is it possible to get image EXIF and rotate image according to it?

Black strips on resized image

When I'm resizing image some strange black borders appear on thumbnail.
My code is:

            /*
             * Save thumbnail image
             */
            $thumbPath=$dir . '/' . self::getThumbPrefix() . $image->name;
            $saved=Yii::$app->image->load($path)
                ->resize(self::THUMB_WIDTH, self::THUMB_HEIGHT, yii\image\drivers\Image::INVERSE)
                ->crop(self::THUMB_WIDTH, self::THUMB_HEIGHT)
                ->save($thumbPath, $quality = 100);
            if($saved==false)
                throw new HttpException(500, 'Unable to save image thumbnail.');

Original image:

reczycz_belapan150714-4r4ub

Final image:

224x224_1_1436904097

Please check top and bottom borders. Do you know why does it happen?

watermark

Hi. I use

$image=Yii::$app->image->load($dir.$model->image->name);
$watermark = Yii::$app->image->load($dir.'wt.png');
$image->watermark($watermark)->save($dir.'___'.$model->image->name);

and get an error

Argument 1 passed to yii\image\drivers\Kohana_Image::watermark() must be an instance of yii\image\drivers\Image, instance of yii\image\drivers\Image_GD given, called in F:\OpenServerLast\domains\portf.ru\backend\protected\modules\admin\controllers\DefaultController.php on line 111 and defined

obj $watermark:

object(yii\image\drivers\Image_GD)[61]
protected '_image' => string 'F:\OpenServerLast\domains\portf.ru\frontend\web\uploads\test\wt.png' (length=67)
protected '_create_function' => string 'imagecreatefrompng' (length=18)
public 'file' => string 'F:\OpenServerLast\domains\portf.ru\frontend\web\uploads\test\wt.png' (length=67)
public 'width' => int 20
public 'height' => int 20
public 'type' => int 3
public 'mime' => string 'image/png' (length=9)

Help Me Please

how to save change

hi . thank for this.
i try save change to image on local file or save new image chang to localhost but i cant do it .please help me..

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.