Windows: Jscript convert result not same as cmd convert

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?".
Post Reply
AKJ
Posts: 3
Joined: 2011-06-02T08:42:09-07:00
Authentication code: 8675308

Windows: Jscript convert result not same as cmd convert

Post by AKJ »

Using Windows Vista business. IM-6.7.0-Q16. Javascript and ActiveX. Tested code from "http://hoernle1.de/m/imagick6/masking/index.html", concerning masking for conversion of JPEG to PNG. The code used ran perfectly when using CMD, giving clear transparency. When run with script, converted to transparency, but showed background. Both versions were viewed with "Windows PHOTO Gallery" program, which revealed the difference.

CMD code: im1 -bordercolor white -border 1x1 -alpha set -channel RGBA -fuzz 1% -fill none -floodfill +0+0 white -shave 1x1 im2

Javascript:
imo = new ActiveXObject("ImageMagickObject.MagickImage.1");

Cmd=[" -bordercolor white"," -border 1x1"," -alpha set"," -channel RGBA"," -fuzz 1%"," -fill none"," -floodfill +0+0 none"," -shave 1x1"];

function TransIm(im1,im2,a){
imo.convert(im1,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],im2);
}

Is there a way to ensure that the script produces the same result as CMD? Thanks in advance!
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Windows: Jscript convert result not same as cmd convert

Post by whugemann »

Your sample code is rather sparse. Are you trying to run it in your browser or as a script for the Windows Script Host?
Wolfgang Hugemann
AKJ
Posts: 3
Joined: 2011-06-02T08:42:09-07:00
Authentication code: 8675308

Re: Windows: Jscript convert result not same as cmd convert

Post by AKJ »

Thank you for your reply. Please accept my apologies for the poor post. I will try to be better.

The code is to run in a browser, under hta.

Here is a cut-down working version of the code in question:

<html>
<head>
<title>Test IM with ActX & JS</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type = "text/javascript" language = "Javascript">
<!-- Hide from older browsers;

var imo = new ActiveXObject("ImageMagickObject.MagickImage.1");
var imA='C:\\AA\\XXX.jpg';// a jpg with a tee-shirt on a nominally white background
var imB='C:\\AA\\XXX-trans.png';// the output transparent png image

var Cmd="' -bordercolor white',' -border 1x1',' -alpha set',' -channel RGBA',' -fuzz 1%',' -fill none',' -floodfill +0+0 white',' -shave 1x1'";

imo.convert(imA,Cmd,imB);

var tstr='Test - Type, Size, Colors, FileSize (bytes): '+imo.identify('-format',' %m, %G, %k, %b',imB);
alert(tstr);

/*
The CMD entry that works perfectly:
convert imA.jpg -bordercolor white -border 1x1 -alpha set -channel RGBA -fuzz 1% -fill none -floodfill +0+0 white -shave 1x1 imB.png

Program works fine, but result is NOT transparent - shows white background.

To see the difference in sizes:
XXX.jpg was 504 KB
XXX-trans.png was 1926 KB (from above program)
XXX-trans.png was 2110 KB (from CMD operation)
*/

// end hide -->
</script>
</head>
<body>

</body>
</html>

Please let me know if you require more input.
Thanks
AKJ
Posts: 3
Joined: 2011-06-02T08:42:09-07:00
Authentication code: 8675308

Re: Windows: Jscript convert result not same as cmd convert

Post by AKJ »

Well, after trying a number of approaches, and viewing your excellent page http://www.imagemagick.org/Usage/windows/, I resolved to use Javascript for all functions that would work properly, and run those that gave results which differed from the CMD result, in a batch file.
The following was tested and proved successful, running hidden:

<html>
<head>
<title>Testing Image Batching</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type = "text/javascript" language = "Javascript">

function BatchIt(fNom){
var shell=new ActiveXObject("WScript.Shell");
shell.Run(fNom,0,true); // 0: hide window; true: script halts until batch ends.
shell=null;
}

BatchIt('C:\\{path}\\c03.bat C:\\{path}\\A.jpg C:\\{path}\\A-trans.png'); // A.jpg had white background - to be made transparent.

</script>
</head>
<body>
</body>
</html>

The following batch file named "c03.bat" was used:

@ECHO OFF
convert %1 -bordercolor white -border 1x1 -alpha set -channel RGBA -fuzz 5%% -fill none -floodfill +0+0 white -shave 1x1 %2

All fine.
Thanks for your input and link. Helped a lot!
Post Reply