Page 1 of 1

$image->Label(); not working at all, no errors.

Posted: 2014-06-09T08:20:12-07:00
by tampadavid
Hello again.

This one is adjusting my opinion imagemagick. Noob alert, I am new to perl, so I say this to let you know I know that. Here is a test script I have used to proof the use of $image->Label(); :

Code: Select all

#!/usr/bin/env perl

# perl-jsiiw-Label-fail.pl: test script to learn/fix Image::Magick Label fail.

use strict;
use warnings;
use Image::Magick;

my ($i1, $i2);  # for image files.

my $wtf;  # for error codes.

# we assume the following test images.  These are == to:
# Image1_label_test.png PNG 1432x1080 1432x1080+0+0 8-bit DirectClass 120KB 0.000u 0:00.000
$i1 = Image::Magick->new;
$wtf = $i1->Read("515A.png");
warn $wtf if $wtf;
$wtf = $i1->Label("%f");  # %f   filename
warn $wtf if $wtf;
$wtf = $i1->Write("Image1_label_test.png");
warn $wtf if $wtf;

$i2 = Image::Magick->new;
$wtf = $i2->Read("516A.png");
warn $wtf if $wtf;
#$wtf = $i2->Label(text=>"%f");  # wrong, though you'd not get that from docs.
=pod
"The text parameter for methods, Annotate(), Comment(), Draw(), and Label() can include the image filename, type, width, height, or other image attribute by embedding these special format characters:"  WTF?
=cut
$wtf = $i2->Label('Hello World!');  # Not even a string works.  Tried double quotes too.
warn $wtf if $wtf;
$wtf = $i2->Write("Image2_label_test.png");
warn $wtf if $wtf;

print "\n\nDone.  Now check files.\n";

Simply put: $image->Label(); is not doing anything. Label works from bash, but I cannot get it to work from Image::Magick (PerlMagick). No errors either.

So. What's up with that?

Here's the source for it, from magick-image.c:

Code: Select all

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   M a g i c k L a b e l I m a g e                                           %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  MagickLabelImage() adds a label to your image.
%
%  The format of the MagickLabelImage method is:
%
%      MagickBooleanType MagickLabelImage(MagickWand *wand,const char *label)
%
%  A description of each parameter follows:
%
%    o wand: the magick wand.
%
%    o label: the image label.
%
*/
WandExport MagickBooleanType MagickLabelImage(MagickWand *wand,
  const char *label)
{
  MagickBooleanType
    status;

  assert(wand != (MagickWand *) NULL);
  assert(wand->signature == WandSignature);
  if (wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
  if (wand->images == (Image *) NULL)
    ThrowWandException(WandError,"ContainsNoImages",wand->name);
  status=SetImageProperty(wand->images,"label",label);
  if (status == MagickFalse)
    InheritException(wand->exception,&wand->images->exception);
  return(status);
}
Looks like another pointer to me: const char *label. And I suspect it is being set, but nothing is being done with it.

I figured if this is broken, then there would be lots of traffic about it. But perhaps not so many people use Image::Magick after all? I do not know. Nor do I know why coding according to documentation is failing. I'll try annotate if I have too, but the whole point of label is that it "labels", which I prefer to use on top of images for ecommerce display.

Labeling in Image::Magick just does not seem to do anything, at all.


David

Re: $image->Label(); not working at all, no errors.

Posted: 2014-06-09T09:58:52-07:00
by snibgo
Do you want to:

1. Create an image of the text, like the command line "label:", or

2. Assign a metadata label, like the command line "-label"? (See http://www.imagemagick.org/script/comma ... .php#label)

Task (2), at the command line, needs "-label" before the image is read. Perl is probably the same.

Re: $image->Label(); not working at all, no errors.

Posted: 2014-06-09T13:42:20-07:00
by tampadavid
I am trying to label the image with the filename, which will then be used on the display of a woocommerce page in wordpress. Labels identify the product's filename, which helps to customer verify they are buying the correct slides.

The image itself is a 700x700px png reduction of the full slide (resized via IM), and there are also A/B sequences that are being combined into a gif animation (also in IM).

So like the script shows, I am reading, amending and then writing an image file, from one filename to another filename. The script above is just a proofing exercise which proves that as of now, Label() does not do anything. I can write the statement to error, but I cannot write it to actually label an image. Labeling from bash works, however. So I figure it is Image::Magick/PerlMagick. Just a WAG though.

Try the script yourself. Just rename two png graphic files to the names in the script, and see what does not happen.


David

Re: $image->Label(); not working at all, no errors.

Posted: 2014-06-09T14:21:30-07:00
by snibgo
Sorry, I don't use Perl.

The documentation http://www.imagemagick.org/script/perl-magick.php says Label will "assign a label to an image". You would use "identify verbose" to find if it has succeeded.

Please answer my question:
snibgo wrote:Do you want to:

1. Create an image of the text, like the command line "label:", or

2. Assign a metadata label, like the command line "-label"?
What bash command does what you want?

Re: $image->Label(); not working at all, no errors.

Posted: 2014-06-10T05:35:50-07:00
by tampadavid
I think it is a perl/Image::Magick/PerlMagick thing(ee). I can do these things no problem from the command line (bash). I am using perl because I have LOTS to do with these image source files. Labeling is just one of them.

In the script, I read an image, then attempt to label it with its filename or even a string, and then write it to a different file. And I am doing this according to official, posted documentation. And it is not working. My WAG is that the documentation is incomplete (OK, that one is not a wild ass guess, it is plain to see our documentation is incomplete), it is incorrectly written in perl (nuance), or there is a bug of some sort, that broke this method.

I do not know, and, it is not working, yet.

I'm going to look at further into the source code, since that is the ultimate in documentation, in a round about way.

Thank you for helping with this.


David