New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asset-pipeline for laravel 4.0 #128

Closed
aditya- opened this Issue Feb 20, 2014 · 26 comments

Comments

Projects
None yet
5 participants
@aditya-

aditya- commented Feb 20, 2014

Hi @kdocki

i am using laravel 4.0 . i am using older version of asset-pipeline .. @kdocki can you please suggest some latest stable version of asset-pipeline which is compatible with laravel 4.0 . How to upgrade from old ?

can i optimize my images using this asset-pipeline .. if yes ... how to that ..

Thanks in advance

@GrahamCampbell

This comment has been minimized.

Show comment
Hide comment
@GrahamCampbell

GrahamCampbell Feb 20, 2014

Contributor

Give him a break. It's only been 3 hours!

Contributor

GrahamCampbell commented Feb 20, 2014

Give him a break. It's only been 3 hours!

@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 20, 2014

sorry @GrahamCampbell .. can you suggest anything on this issue

aditya- commented Feb 20, 2014

sorry @GrahamCampbell .. can you suggest anything on this issue

@GrahamCampbell

This comment has been minimized.

Show comment
Hide comment
@GrahamCampbell

GrahamCampbell Feb 20, 2014

Contributor

I don't personally use this package, but it looks like any version is compatible judging by the composer requirement of "4.x". If you want the latest stable version of this package, just require it with the version constraint of "1.x@stable".

Contributor

GrahamCampbell commented Feb 20, 2014

I don't personally use this package, but it looks like any version is compatible judging by the composer requirement of "4.x". If you want the latest stable version of this package, just require it with the version constraint of "1.x@stable".

@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 20, 2014

@GrahamCampbell .. thanks .. can i implement image optimization using the asset-pipeline.. or any better framework is there

aditya- commented Feb 20, 2014

@GrahamCampbell .. thanks .. can i implement image optimization using the asset-pipeline.. or any better framework is there

@GrahamCampbell

This comment has been minimized.

Show comment
Hide comment
@GrahamCampbell

GrahamCampbell Feb 20, 2014

Contributor

Maybe https://github.com/orchestral/imagine would be of some use?

Contributor

GrahamCampbell commented Feb 20, 2014

Maybe https://github.com/orchestral/imagine would be of some use?

@kdocki

This comment has been minimized.

Show comment
Hide comment
@kdocki

kdocki Feb 21, 2014

Contributor

@aditya- You should be able to use the latest version with Laravel 4.0 or 4.1

Contributor

kdocki commented Feb 21, 2014

@aditya- You should be able to use the latest version with Laravel 4.0 or 4.1

@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 21, 2014

@kdocki .. thanks .. bt can i optimize my images using this asset-pipeline .. if yes ... how to that ..

aditya- commented Feb 21, 2014

@kdocki .. thanks .. bt can i optimize my images using this asset-pipeline .. if yes ... how to that ..

@kdocki

This comment has been minimized.

Show comment
Hide comment
@kdocki

kdocki Feb 21, 2014

Contributor

No idea how to optimize images. You might try using that library GrahamCampbell mentioned above though.

Contributor

kdocki commented Feb 21, 2014

No idea how to optimize images. You might try using that library GrahamCampbell mentioned above though.

@kdocki kdocki added the question label Feb 21, 2014

@GrahamCampbell

This comment has been minimized.

Show comment
Hide comment
@GrahamCampbell

GrahamCampbell Feb 21, 2014

Contributor

@aditya- That library I gave you won't optimize them straight off. You will need to write your own code to do it.

Contributor

GrahamCampbell commented Feb 21, 2014

@aditya- That library I gave you won't optimize them straight off. You will need to write your own code to do it.

@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 21, 2014

@kdocki @GrahamCampbell .. i saw this .. https://gist.github.com/Spir/5650030 which is based assetic .. its an image optimization gist file .. i am unable to make it work ... but its good one .. can you please look

aditya- commented Feb 21, 2014

@kdocki @GrahamCampbell .. i saw this .. https://gist.github.com/Spir/5650030 which is based assetic .. its an image optimization gist file .. i am unable to make it work ... but its good one .. can you please look

@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 21, 2014

@Spir can you specify usage instruction .. where i need to keep this in laravel .. as i am getting Class 'Illuminate\Console\Command' not found .. error ..

aditya- commented Feb 21, 2014

@Spir can you specify usage instruction .. where i need to keep this in laravel .. as i am getting Class 'Illuminate\Console\Command' not found .. error ..

@Spir

This comment has been minimized.

Show comment
Hide comment
@Spir

Spir Feb 22, 2014

@aditya- that gist I made a while ago is actually triggering shell commands. You first need to install jpegoptim and optipng that are doing the real job. Commands are saved under app/commands so that's where you should save it. The php artisan dump-autoload and don't forget to register the command:
http://laravel.com/docs/commands#registering-commands

Spir commented Feb 22, 2014

@aditya- that gist I made a while ago is actually triggering shell commands. You first need to install jpegoptim and optipng that are doing the real job. Commands are saved under app/commands so that's where you should save it. The php artisan dump-autoload and don't forget to register the command:
http://laravel.com/docs/commands#registering-commands

@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 22, 2014

@Spir ... Thanks its really a great gist .. Actually is assetic image optimization is a bit complex .. becoz we need to do individually .. so to use this first i need to register like Artisan::add(new ImageOptimize); .. and i need to save gist file at app/commands ... there i need to run right ?

in gist file where to give $imagesFolders path ... how to give like relative path or absolute path ... Please let me know .. Thank you

aditya- commented Feb 22, 2014

@Spir ... Thanks its really a great gist .. Actually is assetic image optimization is a bit complex .. becoz we need to do individually .. so to use this first i need to register like Artisan::add(new ImageOptimize); .. and i need to save gist file at app/commands ... there i need to run right ?

in gist file where to give $imagesFolders path ... how to give like relative path or absolute path ... Please let me know .. Thank you

@Spir

This comment has been minimized.

Show comment
Hide comment
@Spir

Spir Feb 22, 2014

Yeap add folders that contains images like:

$imagesFolders = Array(
    public_path().'/photos/',
    public_path().'/some_more_images/'
);

Then you can do "php artisan list" and see if the command is listed. Then you can launch image optimizations :

php artisan ImageOptimize

Spir commented Feb 22, 2014

Yeap add folders that contains images like:

$imagesFolders = Array(
    public_path().'/photos/',
    public_path().'/some_more_images/'
);

Then you can do "php artisan list" and see if the command is listed. Then you can launch image optimizations :

php artisan ImageOptimize
@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 22, 2014

Awesome @Spir .. Thanks for the lovely script .. i will try this ..

aditya- commented Feb 22, 2014

Awesome @Spir .. Thanks for the lovely script .. i will try this ..

@kdocki kdocki closed this Feb 23, 2014

kdocki added a commit that referenced this issue Feb 23, 2014

@kdocki

This comment has been minimized.

Show comment
Hide comment
@kdocki

kdocki Feb 23, 2014

Contributor

Added some documentation about this for other eyes. Image optimization is a cool thing to do to your assets but as you can see it is probably best for it to be done separately from the pipeline and then just include optimized images into the pipeline.

Contributor

kdocki commented Feb 23, 2014

Added some documentation about this for other eyes. Image optimization is a cool thing to do to your assets but as you can see it is probably best for it to be done separately from the pipeline and then just include optimized images into the pipeline.

@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 24, 2014

@Spir it was working awesome .. today i checked it ... but it lacks when optimizing sub folders ... how to do this optimization in recursive mode ..

like suppose directories are like this : assets/images/pics

i declared like this

$start = new DateTime();

        $imagesFolders = Array(
               app_path().'/assets/images/' );

its optimizing only images and its ignoring pics folder .. how to do this optimization in recursive mode.

aditya- commented Feb 24, 2014

@Spir it was working awesome .. today i checked it ... but it lacks when optimizing sub folders ... how to do this optimization in recursive mode ..

like suppose directories are like this : assets/images/pics

i declared like this

$start = new DateTime();

        $imagesFolders = Array(
               app_path().'/assets/images/' );

its optimizing only images and its ignoring pics folder .. how to do this optimization in recursive mode.

@Spir

This comment has been minimized.

Show comment
Hide comment
@Spir

Spir Feb 24, 2014

The man page for jpeginfo say there are no recursive solution:
http://www.kokkonen.net/tjko/src/man/jpeginfo.txt
Same for optipng:
http://linux.die.net/man/1/optipng

That's the reason why you have to declare every folder unfortunately.
Also I have see there are some fork for those solution. Maybe there is a solution there. I didn't check. And stuff like Gulp and Grunt have some images minification task. Maybe there are better solution there too. I didn't check it yet.

Spir commented Feb 24, 2014

The man page for jpeginfo say there are no recursive solution:
http://www.kokkonen.net/tjko/src/man/jpeginfo.txt
Same for optipng:
http://linux.die.net/man/1/optipng

That's the reason why you have to declare every folder unfortunately.
Also I have see there are some fork for those solution. Maybe there is a solution there. I didn't check. And stuff like Gulp and Grunt have some images minification task. Maybe there are better solution there too. I didn't check it yet.

@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 24, 2014

yeah @Spir i am trying to implement some thing like this

        foreach($imagesFolders as $imagesFolder)
        {
            exec('find .$imagesFolder. -iname *.jpg jpegoptim --max=95 -v --preserve --totals --strip-all --all-progressive {} ');
        }
        $this->info('jpeg optimization done');

which is not working .. i seen this at https://github.com/glennr/jpegoptim

can you give any ideas ?

another ref : http://www.networkinghowtos.com/howto/optimizing-jpeg-image-files-on-linux/

aditya- commented Feb 24, 2014

yeah @Spir i am trying to implement some thing like this

        foreach($imagesFolders as $imagesFolder)
        {
            exec('find .$imagesFolder. -iname *.jpg jpegoptim --max=95 -v --preserve --totals --strip-all --all-progressive {} ');
        }
        $this->info('jpeg optimization done');

which is not working .. i seen this at https://github.com/glennr/jpegoptim

can you give any ideas ?

another ref : http://www.networkinghowtos.com/howto/optimizing-jpeg-image-files-on-linux/

@Spir

This comment has been minimized.

Show comment
Hide comment
@Spir

Spir Feb 24, 2014

There is a nice idea on that last link you gave:
find . -name '*.jpg' | xargs jpegoptim --strip-all
You need to do it like that:

exec('find '.$imagesFolder.' -name *.jpg  | xargs jpegoptim --strip-all');

You can almost do the same for PNG:

exec('find '.$imagesFolder.' -name *.png  | xargs optipng ');

The first link is a fork that you need to install on your own.

Spir commented Feb 24, 2014

There is a nice idea on that last link you gave:
find . -name '*.jpg' | xargs jpegoptim --strip-all
You need to do it like that:

exec('find '.$imagesFolder.' -name *.jpg  | xargs jpegoptim --strip-all');

You can almost do the same for PNG:

exec('find '.$imagesFolder.' -name *.png  | xargs optipng ');

The first link is a fork that you need to install on your own.

@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 24, 2014

Hi ,

@Spir thanks for fast response .. here i given like this :

// jpeg optimization
        foreach($imagesFolders as $imagesFolder)
        {
            exec('find . -name '*.jpg' | xargs jpegoptim --max=95 --strip-all --all-progressive '.$imagesFolder.'*');
        }
        $this->info('jpeg optimization done');

but i am getting syntax error :

PHP Parse error:  syntax error, unexpected '.' in /usr/share/nginx/www/4app/app/commands/ImageOptimize.php on line 57
PHP Stack trace:
PHP   1. {main}() /usr/share/nginx/www/4app/artisan:0
PHP   2. Illuminate\Console\Application::start() /usr/share/nginx/www/4app/artisan:46
PHP   3. require() /usr/share/nginx/www/4app/vendor/laravel/framework/src/Illuminate/Console/Application.php:30
PHP   4. require() /usr/share/nginx/www/4app/vendor/laravel/framework/src/Illuminate/Console/start.php:57
PHP   5. spl_autoload_call() /usr/share/nginx/www/4app/vendor/laravel/framework/src/Illuminate/Console/start.php:14
PHP   6. Composer\Autoload\ClassLoader->loadClass() /usr/share/nginx/www/4app/vendor/laravel/framework/src/Illuminate/Console/start.php:0

can you please suggest

aditya- commented Feb 24, 2014

Hi ,

@Spir thanks for fast response .. here i given like this :

// jpeg optimization
        foreach($imagesFolders as $imagesFolder)
        {
            exec('find . -name '*.jpg' | xargs jpegoptim --max=95 --strip-all --all-progressive '.$imagesFolder.'*');
        }
        $this->info('jpeg optimization done');

but i am getting syntax error :

PHP Parse error:  syntax error, unexpected '.' in /usr/share/nginx/www/4app/app/commands/ImageOptimize.php on line 57
PHP Stack trace:
PHP   1. {main}() /usr/share/nginx/www/4app/artisan:0
PHP   2. Illuminate\Console\Application::start() /usr/share/nginx/www/4app/artisan:46
PHP   3. require() /usr/share/nginx/www/4app/vendor/laravel/framework/src/Illuminate/Console/Application.php:30
PHP   4. require() /usr/share/nginx/www/4app/vendor/laravel/framework/src/Illuminate/Console/start.php:57
PHP   5. spl_autoload_call() /usr/share/nginx/www/4app/vendor/laravel/framework/src/Illuminate/Console/start.php:14
PHP   6. Composer\Autoload\ClassLoader->loadClass() /usr/share/nginx/www/4app/vendor/laravel/framework/src/Illuminate/Console/start.php:0

can you please suggest

@felixkiss

This comment has been minimized.

Show comment
Hide comment
@felixkiss

felixkiss Feb 24, 2014

Contributor

@aditya- your single quotes inside of the bash command needs to be escaped like so

// jpeg optimization
foreach($imagesFolders as $imagesFolder)
{
    exec('find . -name \'*.jpg\' | xargs jpegoptim --max=95 --strip-all --all-progressive '.$imagesFolder.'*');
}
$this->info('jpeg optimization done');
Contributor

felixkiss commented Feb 24, 2014

@aditya- your single quotes inside of the bash command needs to be escaped like so

// jpeg optimization
foreach($imagesFolders as $imagesFolder)
{
    exec('find . -name \'*.jpg\' | xargs jpegoptim --max=95 --strip-all --all-progressive '.$imagesFolder.'*');
}
$this->info('jpeg optimization done');
@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 24, 2014

@felixkiss .. Really thanks for the idea ..

after executing i am getting this output

jpegoptim: can't open /usr/share/nginx/www/4app/public/ico/*
jpeg optimization done
** Processing: /usr/share/nginx/www/4app/public/system/Course
Error: Unrecognized image file format

** Processing: /usr/share/nginx/www/4app/public/system/Free_resource
Error: Unrecognized image file format

** Processing: /usr/share/nginx/www/4app/public/system/img
Error: Unrecognized image file format

** Processing: ./vendor/swiftmailer/swiftmailer/test-suite/lib/simpletest/test/site/search.png
Error: PNG file appears to be corrupted by text file conversions

** Processing: ./vendor/swiftmailer/swiftmailer/test-suite/lib/simpletest/docs/simpletest.org/images/test-with-1-fail.png
491x104 pixels, 3x8 bits/pixel, RGB
Input IDAT size = 14513 bytes
Input file size = 14649 bytes

Trying:
  zc = 9  zm = 9  zs = 0  f = 0     IDAT size = 14513
  zc = 9  zm = 8  zs = 0  f = 0     IDAT size = 14513

./vendor/swiftmailer/swiftmailer/test-suite/lib/simpletest/docs/simpletest.org/images/test-with-1-fail.png is already optimized.

** Processing: ./vendor/swiftmailer/swiftmailer/test-suite/lib/simpletest/docs/simpletest.org/images/simpletest-logo.png
335x127 pixels, 8 bits/pixel, 71 colors in palette
Input IDAT size = 2703 bytes
Input file size = 3098 bytes

its showing it cant access some folders but its optimizing those folders in background ... its working in background .. taking all images in the project

@Spir .. i think instead of declaring paths ... like

$imagesFolders = Array(
        // app_path().'/assets/images/',
        // public_path().'/img/' );

its better to give complete app folder .. so that it will searches all images may be ....

like

exec('find .base_path(). -name \'*.jpg\' | xargs jpegoptim --max=95 --strip-all --all-progressive '.$imagesFolder.'*');

can be done ? i am getting some errors

aditya- commented Feb 24, 2014

@felixkiss .. Really thanks for the idea ..

after executing i am getting this output

jpegoptim: can't open /usr/share/nginx/www/4app/public/ico/*
jpeg optimization done
** Processing: /usr/share/nginx/www/4app/public/system/Course
Error: Unrecognized image file format

** Processing: /usr/share/nginx/www/4app/public/system/Free_resource
Error: Unrecognized image file format

** Processing: /usr/share/nginx/www/4app/public/system/img
Error: Unrecognized image file format

** Processing: ./vendor/swiftmailer/swiftmailer/test-suite/lib/simpletest/test/site/search.png
Error: PNG file appears to be corrupted by text file conversions

** Processing: ./vendor/swiftmailer/swiftmailer/test-suite/lib/simpletest/docs/simpletest.org/images/test-with-1-fail.png
491x104 pixels, 3x8 bits/pixel, RGB
Input IDAT size = 14513 bytes
Input file size = 14649 bytes

Trying:
  zc = 9  zm = 9  zs = 0  f = 0     IDAT size = 14513
  zc = 9  zm = 8  zs = 0  f = 0     IDAT size = 14513

./vendor/swiftmailer/swiftmailer/test-suite/lib/simpletest/docs/simpletest.org/images/test-with-1-fail.png is already optimized.

** Processing: ./vendor/swiftmailer/swiftmailer/test-suite/lib/simpletest/docs/simpletest.org/images/simpletest-logo.png
335x127 pixels, 8 bits/pixel, 71 colors in palette
Input IDAT size = 2703 bytes
Input file size = 3098 bytes

its showing it cant access some folders but its optimizing those folders in background ... its working in background .. taking all images in the project

@Spir .. i think instead of declaring paths ... like

$imagesFolders = Array(
        // app_path().'/assets/images/',
        // public_path().'/img/' );

its better to give complete app folder .. so that it will searches all images may be ....

like

exec('find .base_path(). -name \'*.jpg\' | xargs jpegoptim --max=95 --strip-all --all-progressive '.$imagesFolder.'*');

can be done ? i am getting some errors

@Spir

This comment has been minimized.

Show comment
Hide comment
@Spir

Spir Feb 24, 2014

it looks like you have some broken images

Spir commented Feb 24, 2014

it looks like you have some broken images

@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 24, 2014

@Spir and all the contributors, thank you so much for your help

aditya- commented Feb 24, 2014

@Spir and all the contributors, thank you so much for your help

@aditya-

This comment has been minimized.

Show comment
Hide comment
@aditya-

aditya- Feb 24, 2014

everything is working fine now

aditya- commented Feb 24, 2014

everything is working fine now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment