iwyg / jitimage

Just In Time image manipulation (GD, Imagick, imagemagick) with integration for laravel 4
MIT License
95 stars 8 forks source link

Routes are not working #31

Closed coldKingdom closed 10 years ago

coldKingdom commented 10 years ago

Hello (again)! :)

After some pulling my hair today, I cannot get the routes to work.

I have set images as a route in your config-file and a recipe thumbs with the width and height, but I only get 404 errors and routes aren't working.

Should I set the routes somewhere else too?

If I run JitImage::source('/media/users/'.$item->user_id.'/cars/md/'.$item->uuid.'.'.$item->ext)->fit('200', '200'); I get a URL and a directory "jit" is created in the storage dir, but the jit-dir is empty and 404-error still occurs.

I'm running the latest update from you and Laravel 4.1.24.

Do you have any ideas how to get this to work?

Thank you!

/Andreas

iwyg commented 10 years ago

Routes are disable when using recipes: see here

Using the jitimage class should work though. You sure /media/users/'.$item->user_id.'/cars/md/'.$item->uuid.'.'.$item->ext is an image path and does exist?

coldKingdom commented 10 years ago

Oh, thank you for enlighten me! It does work now when I'm not using recipes. What can be the issue with recipes then?

I would also like the images to be cached as it will be a quite a few images to be loaded at once. Maybe a have missed something crucial there as well..

Edit: Cache is now working now that I put the right environment, the images are saved. But jit/storage-route is not working.

iwyg commented 10 years ago

Recipes prevent your server from being DOS attacked via image manipulation.

There're some insights https://github.com/iwyg/jitimage/issues/30

jit/storage-route is not working

What are you trying to do with that? It's meant for internal use of the image resolver.

coldKingdom commented 10 years ago

But I should be able to access "thumbs" if I created that recipe, right?

Like: /thumbs/media/users/{{ $item->user_id }}/cars/md/{{ $item->uuid.".".$item->ext }} ?

Now when the cache is enabled I get a URL like this

PHP:

<img class="img-responsive" src="{{ JitImage::source('/media/users/'.$item->user_id.'/cars/md/'.$item->uuid.'.'.$item->ext)->resize('0', '120'); }}" alt="">

Translates to:

<img alt="" src="http://domain.se/jit/storage/1dcc8690/jit_a836884eebbd5ada357.jpg" class="img-responsive">
iwyg commented 10 years ago

yes, that's right. that's the path of the cached image.

coldKingdom commented 10 years ago

Yeah, it's excellent. But it doesn't work :) I get 404-errors on the cached images. If i activate recipes I cannot access those either, like thumbs. The only route that is working is images.

iwyg commented 10 years ago

can you quick dump your config?

iwyg commented 10 years ago

also php artisan routes

coldKingdom commented 10 years ago
<?php

return [

    /* ------------------------------------------------
     * the base route:
     * ------------------------------------------------
     */

    'route'      => 'images',

    /* ------------------------------------------------
     * the base directory from where to dynamically resolve
     * images
     * ------------------------------------------------
     */

    'base'       => public_path(),

    /* ------------------------------------------------
     * driver that powers the image manipulation:
     *
     * `gd` (the GDlibraray), `im` (the Imagemagick library),
     *  or `imagick` (this Imagick php extension).
     * ------------------------------------------------
     */

    'driver'      => 'im',

    /* ------------------------------------------------
     * cache settings
     * ------------------------------------------------
     */

    'cache'       => [
    /* ------------------------------------------------
     * cache directory
     * ------------------------------------------------
     */
        'path'         => storage_path(),
    /* ------------------------------------------------
     * base route for resolving cached images
     * ------------------------------------------------
     */
        'route'        => 'jit/storage',
    /* ------------------------------------------------
     * name prefix for cached images
     * ------------------------------------------------
     */
        'prefix'       => 'jit_',
    /* ------------------------------------------------
     * cache processed images only in this environments
     * ------------------------------------------------
     */
        'environments' => ['local']
    ],

    /* ------------------------------------------------
     * the compression quality:
     * 0 - 100
     * ------------------------------------------------
     */

    'quality'     => 80,

    /* ------------------------------------------------
     * imagemagick specific settings:
     * ------------------------------------------------
     */

    'imagemagick' => [
        'path' => '/usr/bin',
        'bin'  => 'convert',
    ],

    /* ------------------------------------------------
     * image filter:
     * ------------------------------------------------
     */

    'filter' => [
        'Circle'    => 'circ',
        'GreyScale' => 'gs',
        'Overlay'   => 'ovly',
        'Colorize'  => 'clrz',
        'Convert'   => 'conv',
    ],

    /* ------------------------------------------------
     * only this expression should be allowed
     *
     * allow mode 2 crop rescale, with a 200x200 px crop and a grey scale
     * filter:
     *
     *  'thumbs' => '2/200/200/5, filter:gs'
     *
     * allow mode 1 resize, with a resize of 800px width
     * greyscale filter:
     *
     *  'gallery' => '1/800/0, filter:gs',
     *
     * allow mode 4 best fit, with a resize of max 800px width
     * and 600px height, no filters:
     *
     *  'preview' => '4/800/600'
     *
     * ------------------------------------------------
     */
    'recipes' => [
        'thumbs' => '4/800/600'
    ],

    /* ------------------------------------------------
     * a list of trusted sites that deliver assets:
     *  e.g. 'http://25.media.tumblr.com'
     *
     *  or as a regexp:
     *
     *  'http://[0-9]+.media.tumblr.(com|de|net)',
     * ------------------------------------------------
     */

    'trusted-sites' => [
    ],

    /* ------------------------------------------------
     * `generic` or `xsend`
     * ------------------------------------------------
     */
    'response-type' => 'xsend'
];

Routes: +--------+----------------------------------------------+----------------------+---------------------------------------------------+----------------+---------------+ | Domain | URI | Name | Action | Before Filters | After Filters | +--------+----------------------------------------------+----------------------+---------------------------------------------------+----------------+---------------+ | | GET|HEAD set-locale/{locale} | | Closure | | | | | GET|HEAD set-encoding/{encoding} | | Closure | | | | | GET|HEAD _debugbar/open | debugbar.openhandler | Closure | | | | | GET|HEAD jit/storage/{id} | | Thapp\JitImage\Controller\JitController@getCached | | | | | GET|HEAD images/{params}/{source}/{filter?} | | Thapp\JitImage\Controller\JitController@getImage | | | | | GET|HEAD / | | HomeController@showWelcome | | | | | GET|HEAD user/signup | | UserController@getSignup | | | | | POST user/signup | | UserController@postSignup | | | | | GET|HEAD user/thanks | | UserController@getThanks | | | | | GET|HEAD user/login | | UserController@getLogin | | | | | POST user/login | | UserController@postLogin | | | | | GET|HEAD widget/login | | UserController@widgetLogin | | | | | GET|HEAD user/logout | | UserController@getLogout | | | | | GET|HEAD user/welcome | | UserController@sendMail | | | | | GET|HEAD user/profile | | UserController@getProfile | | | | | GET|HEAD cars | | carController@index | | | | | GET|HEAD diaries | | DiaryController@index | | | | | GET|HEAD photos | | PhotoController@index | | | | | GET|HEAD api/diaries | | ApiController@diaries | | | | | GET|HEAD api/search/{text} | | ApiController@search | | | | | GET|HEAD users/{id}/profile | viewUser | UserController@show | | | | | GET|HEAD cars/{id} | viewcar | carController@show | | | | | GET|HEAD diaries/{id} | viewDiary | DiaryController@show | | | | | GET|HEAD admin/add/car | | carController@create | auth.admin | | | | POST admin/add/car | | carController@store | auth.admin | | | | GET|HEAD admin/edit/car/{id} | | carController@edit | auth.admin | | | | POST admin/edit/car/{id} | | carController@update | auth.admin | | | | GET|HEAD admin/delete/car/{id}/{delete?} | | carController@destroy | auth.admin | | | | GET|HEAD admin/list/car | | carController@admin_index | auth.admin | | | | POST admin/add/guestbook/{type}/{id} | | GuestbookController@store | auth.admin | | | | GET|HEAD admin/add/diary | | DiaryController@create | auth.admin | | | | POST admin/add/diary | | DiaryController@store | auth.admin | | | | GET|HEAD admin/edit/diary/{id} | | DiaryController@edit | auth.admin | | | | POST admin/edit/diary/{id} | | DiaryController@update | auth.admin | | | | GET|HEAD admin/delete/diary/{id}/{delete?} | | DiaryController@destroy | auth.admin | | | | GET|HEAD admin/list/diary | | DiaryController@admin_index | auth.admin | | | | GET|HEAD admin/add/picture | | UploadsController@create | auth.admin | | | | POST admin/add/picture | | UploadsController@store | auth.admin | | | | GET|HEAD admin/edit/user | | UserController@edit | auth.admin | | | | POST admin/edit/user | | UserController@update | auth.admin | | | | POST admin/edit/userPicture | | UserController@updatePicture | auth.admin | | | | GET|HEAD admin/list/inbox | | InboxController@index | auth.admin | | | | GET|HEAD admin/send/inbox | | InboxController@store | auth.admin | | | | GET|HEAD admin/show/inbox/{id} | | InboxController@show | auth.admin | | | | GET|HEAD admin/show/outbox/{id} | | InboxController@outboxShow | auth.admin | | | | GET|HEAD admin/reply/inbox/{id} | | InboxController@getReply | auth.admin | | | | POST admin/reply/inbox/{id} | | InboxController@postReply | auth.admin | | | | GET|HEAD admin/delete/inbox/{id} | | InboxController@destroy | auth.admin | | +--------+----------------------------------------------+----------------------+---------------------------------------------------+----------------+---------------+

iwyg commented 10 years ago

seems like you're editing the wrong config file.

the route for thumbs recipe should look like

GET|HEAD images/{thumbs}/{source}     | |   Thapp\JitImage\Controller\JitController@getResource

whereas yours says:

GET|HEAD images/{params}/{source}/{filter?} | | Thapp\JitImage\Controller\JitController@getImage

it's the default route when recipes are not set

coldKingdom commented 10 years ago

I'm feeling pretty stupid right now. Thank you for being patient with me. :)

/images/thumbs working like a charm and had to change the response-type to generic also.

You have done a great package with wonderful tools that just works (if you're not Swedish and think backwards :P). Excellent!

iwyg commented 10 years ago

No worries. Glad I could help.