Git Product home page Git Product logo

yii2-glide's Introduction

Yii2 Glide

Yii2 Glide integration.

Glide is a wonderfully easy on-demand image manipulation library written in PHP.

Before you start read Glide documentation to understand what we are doing

Demo

Since this package was created as a part of yii2-starter-kit it's demo can be found in starter kit demo.

Contributing

You can contribute anything you found useful in any convenient way. Any help appreciated.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist trntv/yii2-glide

or add

"trntv/yii2-glide": "^1.0"

to the require section of your composer.json file.

Usage

Add glide configuration:

'components' => [
    ...
    'glide' => [
        'class' => 'trntv\glide\components\Glide',
        'sourcePath' => '@app/web/uploads',
        'cachePath' => '@runtime/glide',
        'signKey' => '<random-key>' // "false" if you do not want to use HTTP signatures
    ],
    ...
]

Then you can output modified image like so:

Yii::$app->glide->outputImage('new-upload.jpg', ['w' => 100, 'fit' => 'crop'])

You can also use trntv\glide\actions\GlideAction to output images: In any controller add (SiteController for example):

public function actions()
{
    return [
        'glide' => 'trntv\glide\actions\GlideAction'
    ]
}

Than use it: /index.php?r=site/glide?path=new-upload.jpg&w=100&h=75

Example

Complex Glide integration example can be found here

Secure Urls

TBD

yii2-glide's People

Contributors

andrew72ru avatar biserantonov avatar ddinchev avatar spell6inder avatar spiritbox avatar theelk avatar vitaliy7711 avatar webdevsega 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-glide's Issues

How to add access control to glide, only login user can download file

I developed a web app using yii2-starter-kit with yii2-glide, but our security testing engineer told me it is not safe to allow guest to download files.

I have tried to add globalAccess in file storage/config/base.php

`
'as globalAccess'=>[

    'class'=>'\common\behaviors\GlobalAccessBehavior',
    'rules'=>[
        [
            'controllers'=>['glide'],
            'allow' => true,
            'roles' => ['@'],
            'actions'=>['index']
        ],
    ]
]

`

I also tried to add code in vendor/trntv/yii2-glide/src/controllers/GlideController.php

public function behaviors() { return [ 'access' => [ 'class' => AccessControl::className(), 'only' => ['index'], 'rules' => [ [ 'allow' => true, 'actions' => ['index'], 'roles' => ['@'], ], ], ], ]; }

neither worked

не обновляется пакет

Похоже надо поправить зависимость
Composer\DependencyResolver\SolverProblemsException] Problem 1 - league/uri 5.x-dev requires league/uri-components ^1.8 -> no matching package found. - trntv/yii2-glide 1.2.2 requires league/uri ^5.0 -> satisfiable by league/uri[5.x-dev]. - Installation request for trntv/yii2-glide ^1.0

Glide not cropping or scaling image

Hi @trntv ,

I have an image that is 1280 x 300 but I want to crop and use only the leftmost 400 pixels and retain the same height so that the final image becomes 400 x 300 without distortion so I setup the Glide URL as follows but the dimensions didn't change at all, what am I doing wrong?

        $imageUrl = Yii::$app->glide->createSignedUrl([
            'glide/index',
            'path' => $model->image_path,
            'w' => 400,
            'h' => 300,
            'fit' => 'fill'
        ], true);

I also tried 'fit' => 'crop', none worked

Thanks for your help.

Adam

Glide and CloudFlare

Good afternoon!
First of all thanks for you work with your extension!

I have some non-trivial problem.
My trntv/yii2-glide version is 1.3.0
PHP 7.1.16
CentOS
using CloudFlare

My problem with displaying images with resized image more than 192px
Next screen video will eloquently explain the problem - http://i.de-v.net/1524404756.webm
As you can see image is creating and shows on the page but after ~5 second it disappears.

Running code

return \yii\helpers\Html::img(
    Yii::$app->glide->createSignedUrl([
        'glide/index',
        'path' => $model->uploadedProductPictures[0]->picture_path,
        'w' => 500
    ], true)
);

Configurations

'controllerMap' => [
    'glide' => '\trntv\glide\controllers\GlideController'
]
...
'glide' => [
    'class' => 'trntv\glide\components\Glide',
    'sourcePath' => '@storage/source',
    'cachePath' => '@storage/cache',
    'maxImageSize' => 4000000,
    'signKey' => 'IsOOUu_ixnoxqrx6jN34IF7TL25yWuT3'
]
...
'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules'=> [
        ['pattern'=>'cache/<path:(.*)>', 'route'=>'glide/index', 'encodeParams' => false]
    ]
]
...

Browser log

t=66267 [st=46025]      HTTP2_STREAM_ERROR
                        —> description = "Server reset stream."
                        —> net_error = "ERR_SPDY_PROTOCOL_ERROR"
                        —> stream_id = 1
t=66267 [st=46025]   -HTTP_TRANSACTION_READ_BODY
                      —> net_error = -337 (ERR_SPDY_PROTOCOL_ERROR)
t=66267 [st=46025]    FAILED
                      —> net_error = -337 (ERR_SPDY_PROTOCOL_ERROR)
t=66267 [st=46025] -REQUEST_ALIVE
                    —> net_error = -337 (ERR_SPDY_PROTOCOL_ERROR)

I have tested with different browsers, computers and networks.

If 'w' (width) parameter less than 192px - working fine.
If i disabling ssl and CloudFlare - also working fine.

Please, advise me with this problem.

Thank you in advance.

Bump yii2-glide version

There are several fixes since 1.2.0. Including a critical error thrown on every request since 2.0.14 in #21 (not yet accepted). Could you bump the version of yii2-glide?

Хорошо бы сделать кэш по прямому url не через php

Делаем url вида: [ 'pattern'=>'/cache/<w:([0-9]+)>/<h:([0-9]+)>/<q:([0-9]+)>/fit:(crop)/crop:(center)/path:(.*)',
'route'=>'glide/index', 'encodeParams' => false]

и кэш складировать по этому пути.

Если такое возможно подскажите как это можно сделать.

HeadersAlreadySentException

Get error in logs after view image

yii\web\HeadersAlreadySentException: Headers already sent in /var/www/localhost/vendor/league/glide/src/Server.php on line 477. in /var/www/localhost/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /var/www/localhost/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /var/www/localhost/vendor/yiisoft/yii2/base/Application.php(392): yii\web\Response->send()
#2 /var/www/localhost/web/index.php(12): yii\base\Application->run()
#3 {main}

Extensions requirements in documentation

Install manual and Readme has no information about required php extensions – php-exif, for example (and I don`t know, what else).

Glide install manual also has no information, and NotSupportedExeption in actions\GlideAction doesn’t show, why not supported :)

It would be better to add all of this in documentation.

Clear image cache

Hi. If I change any photo and show this with glide, I see old image until manually delete cache file.

Here is issue thephpleague/glide#7 about this, and method deleteCache now in library code.

I think, if You update a league/glide version in composer.json, and all will work out the box. Or, may be, such method already exists, and I do not know about this?

P.S. Thank You for great extension, and sorry my terrible English :)

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.