#11 2011-07-23 18:47

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,480

Re: Is it possible to append to jpg names the number of unique colors?

Indeed, the problem was in ExecConsoleApp function. I use pipes to redirect output of the console applications. What I wasn't aware of is that pipes use fixed buffer size of system default size if not specified explicitly, which seems to be very small like 4K. The target process would freeze when pipe gets full, while ReNamer would wait (infinitely) until the target process terminates before reading the data from the pipe.

So, I no longer wait for the process to terminate to read its output, I read the data as it becomes available. Problem is fixed. Try latest development version smile

const
  MAGIK = '"C:\Tools\ImageMagick-6.7.1-0\identify.exe" -unique -verbose';
  FIND = 'Colors: (\d+)';
var
  Command, Output: String;
  Matches: TStringsArray;
begin
  Command := MAGIK + ' "' + FilePath + '"';
  ExecConsoleApp(Command, Output);
  Matches := SubMatchesRegEx(Output, FIND, False);
  if Length(Matches) > 0 then
    FileName := Matches[0] + ' ' + FileName;
end.

Online

#12 2011-07-24 08:31

Tatjana
Member
From: Portugal
Registered: 2011-01-16
Posts: 5

Re: Is it possible to append to jpg names the number of unique colors?

I did it!!! :-)

My installed version of ImageMagick is different, and I couldn't make the -unique work
(didn't try with -verbose)

So I used -format and "%k" to make it output exactly the number of unique colors and nothing else,
so there is no need to parse the output.

By the way, this script will work for any kind of image file ImageMagick supports, not only jpeg.


Thank you very much for your help, Andrew, Stefan and Denis! You are the best!

Tatjana

PS: sorry for my bad English. Portuguese gal here smile

const
  MAGIK = '"C:\Programas\ImageMagick-6.6.5-Q16\identify.exe" -format "%k"';
var
  Command, Output: String;
  Matches: String;
begin
  Command := MAGIK + ' "' + FilePath + '"';
  ExecConsoleApp(Command, Output);
  Matches := Output;
  if Length(Matches) > 0 then
    FileName := Matches + ' ' + FileName;
end.

Last edited by Tatjana (2011-07-24 08:33)

Offline

#13 2011-07-24 08:50

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Is it possible to append to jpg names the number of unique colors?

Thanks a lot for the fix Denis, and thanks to Tatjana too, otherwise this issue might not have come to light. smile BTW, that "-format" option was a good find. More help on other format options here, in case anyone wants to extract other data.

P.S. For testing purposes I downloaded the portable version of ImageMagick from the official site, as I wasn't interested in installing it, then uninstalling, cleaning up leftover files and registry entries etc.

Offline

Board footer

Powered by FluxBB