asset-pipeline for laravel 4.0
aditya- opened this issue · 26 comments
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
Give him a break. It's only been 3 hours!
sorry @GrahamCampbell .. can you suggest anything on this issue
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".
@GrahamCampbell .. thanks .. can i implement image optimization using the asset-pipeline.. or any better framework is there
Maybe https://github.com/orchestral/imagine would be of some use?
@kdocki .. thanks .. bt can i optimize my images using this asset-pipeline .. if yes ... how to that ..
No idea how to optimize images. You might try using that library GrahamCampbell mentioned above though.
@aditya- That library I gave you won't optimize them straight off. You will need to write your own code to do it.
@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
@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- 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 ... 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
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
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.
@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.
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.
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/
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.
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- 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');
@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
it looks like you have some broken images
everything is working fine now