[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] graphics



At 8.24 -0500 2000.01.23, Paul Schinder wrote:
>At 10:54 PM -0800 1/22/00, Bruce Van Allen wrote:
>>Here's what I plan to investigate, hoping for some suggestions before I
>>resume development next month:
>>
>>1. Use GD ??
>
>Works under MacPerl, not sure if it resizes.  I don't know whether
>Chris or Arved have built the latest versions, which only do PNG, or
>have stuck to the last GIF version.

I was not able to get GD to build with PNG (I just didn't try hard enough,
I'm sure :); in any event, GD can only do GIF or PNG, not JPG.



>>2. Use ImageMagick/PerlMagick ??
>>   $image->Set(size=>[string]); #looks useful!
>>(http://www.wizards.dupont.com/cristy/www/perl.html)
>
>Good solution, but PerlMagick won't work under MacPerl.  However, I
>believe ImageMagick itself does, although I don't know if the port
>knows anything but the four basic AppleEvents.

I believe it could be made to work with PerlMagick, but someone needs to do
the work.  :-)



>Someone has mentioned clip2gif, which is a good solution.

It might be the best bet.


At 23.56 -0800 2000.01.22, Enrique Terrazas wrote:
>There is even an example for use with MacPerl (although it doesn't utilize
>Chris' Glue:
>
>---
>With MacPerl
>
>To run AppleScript code, use the function &MacPerl'DoAppleScript. The
>easiest way to use it is with a "here document". Here is an example:
>
>$w = 100;
>$h = 100;
>$data = '{100,{65535,0,0},60,{0,65535,0},80,{0,0,65535},120}';
>&MacPerl'DoAppleScript(<<eof);
>tell app \"clip2gif\"
>    set dr to {{chart data:$data,chart style:pie,position:{0,0,$w,$h}}}
>    save {$w,$h} in window drawing dr
>end
>eof
>
>See how you can mix Perl variables and code. Note also that quotes must be
>escaped.
>---


Note that they use {} for both lists and records inthe above AppleScript;
it is better style IMO to use {} for records and [] for lists in
AppleScript, which translate exactly into {} for hashes and [] for arrays
in Perl.  I would have done it like this:

#!perl -w
$w = 100;
$h = 100;
$data = '[100,[65535,0,0],60,[0,65535,0],80,[0,0,65535],120]';
&MacPerl'DoAppleScript(<<eof);
tell app \"clip2gif\"
    set dr to [{chart data:$data,chart style:pie,position:[0,0,$w,$h]}]
    save [$w,$h] in window drawing dr
end
eof
__END__


Here is a Mac::Glue version:

#!perl -w
use strict;
use Mac::Glue ':all';

my($c2g, $data, $dr, $w, $h);

($w, $h) = (100, 100);
$c2g = new Mac::Glue 'clip2gif';
$data = [100, [65535, 0, 0], 60, [0, 65535, 0], 80, [0, 0, 65535], 120];
$dr = [{
  chart_data => $data, chart_style => enum('pie'), position => [0, 0, $w, $h]
}];

$c2g->save([$w, $h], in => param_type(window => typeType), drawing => $dr);
die $^E if $^E;

__END__


Note the only significant differences here from the AppleScript version are
the additions of the param_type() and enum() functions.  enum() tells
Mac::Glue that pie is not a string, but a class (in AppleScript this is
denoted by using a bareword).

I am not sure why param_type() is necessary; for some reason, it was coming
out as kfil:cwin instead of the desired kfil:type(cwin).  So we explicitly
tell Mac::Glue to render it as typeType.  There may be some logic I can add
to Mac::Glue so this is not necessary, but I don't offhand know what that
would be.  Oh well.

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org