duplicate methods ?

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

duplicate methods ?

Post by Xandros »

Hello

i'd like to know if there are subtle differences between, for example, MagickSetImageCompression and MagickSetCompression ?

There are a few other couples of methods which according to the documentation appear to be doing 100% the same thing. Is that true ?

Which one is better to use in order to avoid future deprecation ?

thanks !
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: duplicate methods ?

Post by magick »

MagickSetCompression() is to set the compression before an image is created and MagickSetImageCompression() is to set the compression after an image is created. If you call MagickSetCompression() before an image is created, it is inherited when the image is created. If you call MagickSetImageCompression() after an image is created, it sets the compression attribute of the image.
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: duplicate methods ?

Post by Xandros »

ok thanks, as this subtile difference is not documented, it's valuable to know it !

so, as I understand it now, MagickSetCompression is only necessary when creating images from blank canvas, and is never needed if for example only converting between different file types.

The order would then be : read image, resize/transform, use MagickSetImageCompression to choose destination compression, write image to file.

is all that right ?

P.S. A little additional question regarding the ability to reduce memory consumption when reading image from file. on the command line, one uses

convert source.jpg[200x200] -resize "200x200" dest.jpg

How to achieve the same optimization with MagickWand functions please ? the read/resize/write functions are obvious, but the red text part ?... Specify the [200x200] directly inside the "filename" parameter of the MagickReadImage function ?

Thanks !
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: duplicate methods ?

Post by magick »

Just use it within the filename as you suggested. A filename appended with a geometry within brackets is an inline resize. You may instead be looking for the size hint which in modern versions of ImageMagick is set with jpeg:size (e.g. convert -debug jpeg:size 200x200...).
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: duplicate methods ?

Post by Xandros »

OK, didn't know about the jpeg:size thing, where can I find more details ? is it working for other file types ?

I read on the "usage" sample pages that it reduces memory consumption to append the geometry in brackets when creating thumbnails, so the -resize doesn't have much to do afterwards...
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: duplicate methods ?

Post by magick »

The size hint only works with JPEG. Inline cropping (e.g. image.jpg[200x200+10+20]) and resizing (e.g. image.jpg[100x100]) can save some memory but are most beneficial for wildcards (e.g. *.jpg[200x200]). In general, 'image.png[100x100]' is the same as 'image.png -resize 100x100'.
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: duplicate methods ?

Post by Xandros »

oh ok, it's -define jpeg:size=... i see ! is there an magickwand equivalent for this ? MagickImageSetProperty('jpeg:size', '..') ?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: duplicate methods ?

Post by magick »

Right.
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: duplicate methods ?

Post by Xandros »

Great ! Thanks for all the help !
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: duplicate methods ?

Post by Xandros »

Hello
me again ..


MagickResetIterator and MagickSetFirstIterator do both set the iterator to the first image, arent those duplicate ? :)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: duplicate methods ?

Post by magick »

No, the methods behave differently. Reset means give me the 1st image in the container when MagickNextImage() is called whereas MagickSetFirstIterator() causes MagickNextImage() to return the second image in the container.
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: duplicate methods ?

Post by Xandros »

Mm, strange ... Maybe I missed something ?...

Code: Select all

WandExport void MagickSetFirstIterator(MagickWand *wand)
{
  assert(wand != (MagickWand *) NULL);
  assert(wand->signature == WandSignature);
  if (wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
  wand->active=MagickTrue;
  wand->pend=MagickFalse;
  wand->images=GetFirstImageInList(wand->images);
}


WandExport void MagickResetIterator(MagickWand *wand)
{
  assert(wand != (MagickWand *) NULL);
  assert(wand->signature == WandSignature);
  if (wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
  wand->active=MagickFalse;
  wand->pend=MagickTrue;
  wand->images=GetFirstImageInList(wand->images);
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: duplicate methods ?

Post by magick »

Notice the active and pend members have different values?
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: duplicate methods ?

Post by Xandros »

hmm, nope :) well actually I do now :) have read too much code lately I guess :) sorry
Post Reply