when creating thumbnails, c. 15% of the time negative of ori

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
farmkittie

when creating thumbnails, c. 15% of the time negative of ori

Post by farmkittie »

Hello,

I have inherited a problem that I have been asked to resolve: anout 15% of the time the thumbnails that are generated via Perl and Image::Magick come out as "negatives". I am brand new to Image::Magick and have been reading anything I can get my hands on. Would negate and/or solarize convert them back? Really I would like to find a way to automatically correct any of these negatives though.

Ever see anything like this? Thanks in advance for your time and help.

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

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by magick »

Which version of ImageMagick are you using? Post a URL to one or two of your images along with a short PerlMagick script that illustrates the problem. We need to reproduce the problem before we can offer you a solution.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by anthony »

I have seen this before, years ago, though was unable to fugure out what the cause was. Is your image input X bitmaps? Or some other format?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
farmkittie

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by farmkittie »

Thank you Anthony and Magick for your replies. I am posting the stripped down code that I am using to test different attributes to see if any of them will help with my problem. I have a few tries commented out. Of course, "negate" works to reverse the image but the trick would be to do this only when the thumbnails come out "black". Is there an sttribute or other means to detect how much white there is (or black) in a resulting thumbnail and then only switch those with some percentage of black in the thumbnail? It may not be 100% but it would cut down on the number of images that need to be inverted (negated) by hand.

here is the code:

Code: Select all

#!/data/share/prgs/perl
# make_thumbnails.pl
#2007_02_19

use strict;
use lib qw(/data/share/perllib);
#use gdls::common;
use gdls::file_utilities;
#use gdls::exportfileio;
use Image::Magick;

my @attribfields	= qw(type width height x-resolution y-resolution gamma filter format class base_filename); # compression
my @otherfields	= qw(action);

my $image = Image::Magick->new;
my $sourcedir		= "/home/basbergb/original";
my $thumbnaildir	= "/data/share/bb/thumbnail";

my $errno = undef;
my $retval= undef;
my $line = undef;

unless(-d $sourcedir)
{	file_utilities::makedir($sourcedir, "/") ;
	chmod 0777,$sourcedir;
}

unless(-d $thumbnaildir)
{	file_utilities::makedir($thumbnaildir, "/") ;
	chmod 0777,$thumbnaildir;
}

my @files;
{	opendir(my $dh, $sourcedir) or die "can't opendir $sourcedir: $!";
	my @f = readdir($dh);
	closedir $dh;
	chdir $sourcedir or die "Can't change to directory: $sourcedir\n";
	foreach (@f)
	{	push(@files, $_) if(-f && m/\.tif$/i); # skip non-TIFF files
	}
	@files = sort @files;
}

# print "Checking: $sourcedir (".(scalar @files).")\n";
my $fh;

foreach my $f (@files)
{	next if(-d $f || -l $f);

	@$image = ();

	(my $newfile = $f) =~ s/\.tif$/\.jpg/i;
	#(my $newfile = $f) =~ s/\.tif$/\.jpg/i;
	$errno = 0;
	$retval = $image->Read("$sourcedir/$f");
	$retval = "Exception 999: Could not load image." if($retval eq "" && !scalar @$image);
	if($retval)
	{	$errno = $1 if($retval =~ m/^Exception (\d+):/);
	        print "error - $line\n";
		next;
	}

	if(int($errno) < 400)
	{	my @imgattr = $image->Get(@attribfields);
		foreach (@imgattr){$_ = "" unless(defined $_);}
		print "attrib :  @imgattr\n";
		$image->Resize(geometry=>'150x150', density=>'300x300', filter=>'Hermite', support=>1.1);
		$image->Thumbnail(geometry=>'150x150');
#worked		$image->Negate(gray=>1);
#nothin'	$image->Solarize(factor=>75);
#bummer		$image->Threshold(threshold=>.6);
		$image->Write(filename=>"$thumbnaildir/$newfile", compression=>'JPG', quality=>75);
		chmod 0666,"$thumbnaildir/$newfile";
	}
}

undef $image;
How do I determine which version of ImageMagick that I have? Is there a command with a -v flag or some such? I will find an example of a reversed thumbnail and post that as soon as I can. I have to find one that isn't protected by our company policy. In other words I am not allowed top post anything proprietary.

Thanks very much for your help!!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by Bonzo »

You should be able to use -identify but it never worked for me.

Anthony has posted this bit of code which will tell you.

Code: Select all

<?php
header("Content-Type: text/plain"); 
system("exec 2>&1; convert -version"); 
?>
farmkittie

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by farmkittie »

Hello again. How do I post image files as requested by Magick? I have an example of one that shows the negative/reverse video when it is transformed to a thumbnail. I will look for one that does not do this when processed with the same program (code posted above). We also have color pictures but they have never reversed colors (if that's a clue?).

BTW, I cannot give you a URL to them as we are behind a firewall and do not have rights to post anything on the company website that's outside the firewall.
Thanks.
farmkittie

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by farmkittie »

Thanks bonzo, but we don't have php :( and we cannot download and install open source :( :cry:
farmkittie

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by farmkittie »

I believe we have version 6.2.3 of ImageMagick.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by Bonzo »

You need to put it on the web somewhere then add a link to it.

If magick or Anthony read this they may tell you how you could email it to them or use some other method.

I only use php and seeing your last post I can see php is not of any help !

Sorry :?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by Bonzo »

I am using 6.2.8 and have never had a problem with thumbnails.
farmkittie

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by farmkittie »

Thanks Bonzo. You have been helpful, thanks!
farmkittie

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by farmkittie »

Please do let me know where I can email the graphics files as I do not have access to a public website to publish them to.

Thanks.
farmkittie

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by farmkittie »

I forgot to answer one of Anthony's questions:
Is your image input X bitmaps? Or some other format?


the answer is that the imput images are in TIFF.
farmkittie

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by farmkittie »

Anthony, I am wondering if this is related to my problem (an earlier post that you addressed in 2003):
viewtopic.php?p=18186

Specifically, I was googling for answers and found references to the photometric interpretation of TIFF files. Unrelated to Image::Magick but just in general that some software "autocorrects" for this and some do not change what is read from the given TIFF. Is there a method to check for this value in a TIFF file and then I could negate or not based on its setting. I am using Perl and Image::Magick to process TIFF files.

Thanks!
farmkittie

Re: when creating thumbnails, c. 15% of the time negative of ori

Post by farmkittie »

Latest news: :idea: The tiff files that I have been processing show "min-is-black"(photometric interpretation) for those that end up correctly processed (not inverse video) when processed by Image::Magick perl module but show "min-is-white"(photometric interpretation) for those tiff images that end up in negative/reverse video after processing. I used the command tiffinfo at the unix command line with the filename of the tiff in question to see the photometric interpretation value.

My question is: is there a parameter in Image::Magick that I can set to negate() those files that have "min-in-white"? If there is not one, can one be exposed to allow this?

You would be almost saving my life if you can help with this :wink:
Post Reply