Skip to content
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
Closed

asset-pipeline for laravel 4.0 #128

aditya- opened this issue Feb 20, 2014 · 26 comments
Labels

Comments

@aditya-
Copy link

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
Copy link
Contributor

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

@aditya-
Copy link
Author

aditya- commented Feb 20, 2014

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

@GrahamCampbell
Copy link
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".

@aditya-
Copy link
Author

aditya- commented Feb 20, 2014

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

@GrahamCampbell
Copy link
Contributor

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

@kdocki
Copy link
Contributor

kdocki commented Feb 21, 2014

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

@aditya-
Copy link
Author

aditya- commented Feb 21, 2014

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

@kdocki
Copy link
Contributor

kdocki commented Feb 21, 2014

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

@GrahamCampbell
Copy link
Contributor

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

@aditya-
Copy link
Author

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-
Copy link
Author

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
Copy link

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-
Copy link
Author

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
Copy link

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-
Copy link
Author

aditya- commented Feb 22, 2014

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

@kdocki
Copy link
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-
Copy link
Author

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
Copy link

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-
Copy link
Author

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
Copy link

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-
Copy link
Author

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
Copy link
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');

@aditya-
Copy link
Author

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
Copy link

Spir commented Feb 24, 2014

it looks like you have some broken images

@aditya-
Copy link
Author

aditya- commented Feb 24, 2014

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

@aditya-
Copy link
Author

aditya- commented Feb 24, 2014

everything is working fine now

chrisrobert43 added a commit to chrisrobert43/asset-pipeline that referenced this issue Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants