Forums / Developer / Imagemagick resize option with caret (^)

Imagemagick resize option with caret (^)

Author Message

Piotrek Karaś

Saturday 17 May 2008 2:25:22 am

I'm trying to use imagemagick's resize option with minimum image size limit parameter, which is a caret (^). Unfortunately, it fails. Here's an example:

Filters[]
Filters[]=square=-resize %1x%2^ -crop %3x%4+0+0 -gravity center

Something wrong with that filter, eZ Publish, or maybe the library itself? The result is:

Failed executing... Error code: 1

Thanks,
Piotrek

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Bartek Modzelewski

Saturday 17 May 2008 9:37:15 am

Hi Piotrek,

have you tried to execute your command directly in command line using <i>convert</i> ?

Bartek

Baobaz
http://www.baobaz.com

Piotrek Karaś

Sunday 18 May 2008 1:08:32 am

Hey Bartek,

Thanks for the tip - I keep forgetting the differences between gd and imagemagick ;)

So, the thing was not an error, but a version problem - this caret option is a relatively new solution (which by the way is totally curious to me... so many years without a basic geometry setting...). None of my version supports that, so I found another filter trick:

Filters[]=squarefix=-resize x%1 -resize '%1x<' -resize 50% -gravity center -crop %2x%3+0+0 +repage

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

*- pike

Monday 28 July 2008 7:50:45 am

Hi

I'm trying to tackle the same problem. With the caret, my command would be

Filters[]=imthumb48=-scale 48x48^ -crop 48x48! -gravity Center 

but you need im 6.3.8-2 :

> http://www.imagemagick.org/script/changelog.php
> 2008-01-24 6.3.8-2 Cristy <quetzlzacatenango@image...>
> Support a ^ meta character in an image geometry (.e.g convert 640x480.png -resize 240^ returns a 320x240 result).

can you explain how your voodoo works ?

Filters[]=squarefix=-resize x%1 -resize '%1x<' -resize 50% -gravity center -crop %2x%3+0+0 +repage

curious,
*-pike

---------------
The class eZContentObjectTreeNode does.

Piotrek Karaś

Monday 28 July 2008 8:53:52 am

Hi,

I found that instruction as one of the possible workarounds of the caret problem, somewhere in a IM forum. It is supposed to scale down, down to the smaller picture size, and it uses some resize to read image sizes (as far as I remember, IM had some inconveniency about reading that). Unfortunately, I won't be able to decode that word by word - I'm IM beginner ;)
Oh, and that one in particular is used for square images only, I think.

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

*- pike

Friday 29 August 2008 2:55:08 pm

Hi

After two espressoos I could suddenly read it. For a short moment. Let me see if I can repeat that :-)

Filters[]=squarefix=-resize x%1 -resize '%1x<' -resize 50% -gravity center -crop %2x%3+0+0 +repage
[mythumb]
Filters[]=squarefix=96;48;48

-resize x%1 resizes to height 96. the width is chosen to maintain the aspect ratio

-resize '%1x<' sizes UP until the width minimally 96, if required. this will happen if you have a vertical (portrait) image.

-resize 50% scales it down to, not accidently, 48>x48>

-gravity center -crop %2x%3+0+0 +repage then crops to 48x48 centered. not sure why the gravity is before the crop.

I guess that would always work, the only problem is it sizes up for vertical images, eg 133% for a 3x4 image. I'm not sure if IM makes that blurry.

$2c,
*-pike

.

---------------
The class eZContentObjectTreeNode does.

Piotrek Karaś

Tuesday 09 September 2008 9:22:21 pm

Those espressos must have been black as hell! ;)

Yes, this method sometimes produced blury results, but that it mostly limited to a situation where the source image is relatively small. Otherwise, seems to work fine for me.

And yes, you may differ this about resizing order and size, depending on whether you expect more horizontal or vertical images, for better results. In my case, I wanted rectangular images, and decided not to pay much attention to that problem since there was no way of telling that.

It's surprising that all key, and apparently basic functionalities, have been introduced so recently... (speaking the caret)...

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu