nginx-image-filter-watermark icon indicating copy to clipboard operation
nginx-image-filter-watermark copied to clipboard

Resize and crop by any single dimension

Open mguryanov opened this issue 7 years ago • 4 comments

This changes serve to reduce image by any single dimension value. Hidden dimension is implicitly calculated as current image size.

mguryanov avatar Feb 21 '18 11:02 mguryanov

Please fix in README alias /path/to/backgraund/image; to alias /path/to/background/image;

muxx avatar Feb 21 '18 11:02 muxx

I think it will be more correctly if you show examples for existing location which were before in README because your location examples not give any specific info. Thanks.

muxx avatar Feb 21 '18 12:02 muxx

Ok, you're rigth. I will do it, but your location examples not correct. This module can't handle multiple action like crop and resize.

this location chunk

       image_filter                resize $resize_width $resize_height;
       image_filter                crop   $crop_width $crop_height;

effect only last action - crop :)

mguryanov avatar Feb 21 '18 12:02 mguryanov

In confirmation latest comment, we use nginx-image-filter about 2y+ in production. Multi-stage image modification can achieved by using proxy_pass wheel, for example

	##
	# CORRECT sequential image processing : ie crop after resize
	##

        location ~ ^/r/(?<resize_width>\d+|-)?x(?<resize_height>\d+|-)?/(?<img>[^/]+)$ {
		##
		# resize
		##
                image_filter resize $resize_width $resize_height;
                alias /path/to/image/$img;
        }

        location ~ ^/(?<resize>r/(?:\d+|-)?x(?:\d+|-)?)/c/(?<crop_width>\d+|-)?x(?<crop_height>\d+|-)?/(?<img>.+)$ {
		##
		# resize redirect
		##
                proxy_pass http://127.0.0.1/$resize/$img;

		##
		# crop
		##
                image_filter crop $crop_width $crop_height;
        }

unfortunately your configuration take handle only cropping, because there settings masquerade resizing

	##
	# INCORRECT sequential image processing : crop only, never resize
	##

        location ~ ^/intaro/r/(?<resize_width>\d+|-)x(?<resize_height>\d+|-)/c/(?<crop_width>\d+|-)x(?<crop_height>\d+|-)/(?<img>.+) {
                alias                       /Users/goshan/Sites/Zot/Zot/web/$img;

                try_files                   "" @404;

		#
		# Bad logic
		#
                image_filter                resize $resize_width $resize_height;
                image_filter                crop   $crop_width $crop_height;
	}

how to check it? for example, we have image gdlogobig.png ( 336 x 218 ) according request - first step is resizing, and last is cropping, resizing checks by setting one dimension to lesser (50) when orignal value (336), and cropping values sets to originals (336 x 218)

http://localhost/intaro/r/50x218/c/336x218/gdlogobig.png 	<== INCORRECT, image not changed, because crop settings masquarade resizing
http://localhost/r/50x218/c/336x218/gdlogobig.png		<== CORRECT, image changed - resizing happened

mguryanov avatar Feb 26 '18 10:02 mguryanov