diff --git a/Changes b/Changes index dff6c1c..266f77f 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,9 @@ Revision history for GD::Raw {{$NEXT}} +0.5 2026-xx + - Add functions `gdImageEllipse` and `gdImageRectangle` to draw outline ellipses and outline rectangles. + 0.4 2024-10-23T11:02:05+02:00 - Add some in-place filters: 0racle++ diff --git a/META6.json b/META6.json index a6ec075..0d46854 100644 --- a/META6.json +++ b/META6.json @@ -24,5 +24,5 @@ ], "test-depends": [ ], - "version": "0.4" + "version": "0.5" } diff --git a/lib/GD/Raw.rakumod b/lib/GD/Raw.rakumod index e9b7557..0995716 100644 --- a/lib/GD/Raw.rakumod +++ b/lib/GD/Raw.rakumod @@ -191,6 +191,11 @@ sub gdImageFilledEllipse (gdImagePtr $im, int32 $cx, int32 $cy, int32 $w, int32 # returns void is native(LIB) is export {*} +sub gdImageEllipse (gdImagePtr $im, int32 $cx, int32 $cy, int32 $w, int32 $h, + int32 $color) + # returns void + is native(LIB) is export {*} + sub gdImageCopyResized(gdImageStruct $dst, gdImageStruct $src, int32 $dstX, int32 $dstY, int32 $srcX, int32 $srcY, @@ -301,6 +306,10 @@ sub gdImageFilledRectangle(gdImagePtr $im, int32 $x1, int32 $y1, int32 $x2, int3 #returns void is native(LIB) is export {*} +sub gdImageRectangle(gdImagePtr $im, int32 $x1, int32 $y1, int32 $x2, int32 $y2, int32 $color) + #returns void + is native(LIB) is export {*} + class gdPoint is repr('CStruct') is export { has int32 $.x is rw = 0; has int32 $.y is rw = 0; @@ -541,6 +550,64 @@ origin as possible. LibGD is large and this module far from covers it all. Feel free to add anything your missing and submit a pull request! +=head1 MEMORY MANAGEMENT + +When creating an in-memory image, some memory is allocated in GD. This +memory is not automatically deallocated when the variable which refers +to the image goes out of scope. To counter this possible memory leak, +the simplest way is to use the C phaser and call function +C like this + +=begin code :lang + +my $img = gdImageCreateFromPng($fh); +LEAVE gdImageDestroy($_) with $img; + +=end code + +If a program creates several images, there will be a problem if the +program reuses the C<$img> variable. In this case, you cannot use the +C phaser, you must call C before creating the +second image (and the third, and...) + +=begin code :lang + +my $img = gdImageCreateFromPng($fh1); +[...] +gdImageDestroy($img); +$img = gdImageCreateFromPng($fh2); +[...] +gdImageDestroy($img); +$img = gdImageCreateFromPng($fh3); +[...] +gdImageDestroy($img); + +=end code + +Or a simpler solution is to use different variables C<$img1>, +C<$img2>, C<$img3> and so on, and calling C each time +with the C phaser. + +=begin code :lang + +my $img1 = gdImageCreateFromPng($fh1); +LEAVE gdImageDestroy($_) with $img1; +[...] +my $img2 = gdImageCreateFromPng($fh2); +LEAVE gdImageDestroy($_) with $img2; +[...] +my $img3 = gdImageCreateFromPng($fh3); +LEAVE gdImageDestroy($_) with $img3; +[...] + +=end code + +=head1 SEE ALSO + +Raku Module C: L + +C library: L + =head1 AUTHORS =item Dagur Valberg Johannsson @@ -550,7 +617,7 @@ your missing and submit a pull request! Copyright 2013 - 2018 Dagur Valberg Johannsson -Copyright 2024 Raku Community +Copyright 2024, 2026 Raku Community This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0. diff --git a/xt/gdimagerectangle0.rakutest b/xt/gdimagerectangle0.rakutest new file mode 100644 index 0000000..1b6e7a0 --- /dev/null +++ b/xt/gdimagerectangle0.rakutest @@ -0,0 +1,36 @@ +# -*- encoding: utf-8; indent-tabs-mode: nil -*- +use Test; +use GD::Raw; + +use lib $*PROGRAM.parent; +use gdtest; + +plan 1; + +my $im = gdImageCreate(200, 50) or die; +LEAVE gdImageDestroy($im) if $im; + +my $white = gdImageColorAllocate($im, 0xff, 0xff, 0xff); +my $black = gdImageColorAllocate($im, 0, 0, 0); +my $red = gdImageColorAllocate($im, 255, 0, 0); +my $blue = gdImageColorAllocate($im, 0, 0, 255); + +gdImageLine($im, 0, 10, 190, 30, $black); +gdImageFilledEllipse( $im, 10, 20, 20, 20, $white); +gdImageEllipse( $im, 10, 20, 20, 20, $blue); +gdImageFilledRectangle($im, 30, 10, 50, 30, $white); +gdImageRectangle( $im, 30, 10, 50, 30, $blue); +gdImageFilledEllipse( $im, 70, 20, 20, 20, $red); +gdImageFilledRectangle($im, 90, 10, 110, 30, $red); +gdImageSetThickness($im, 3); +gdImageFilledEllipse( $im, 130, 20, 20, 20, $white); +gdImageEllipse( $im, 130, 20, 20, 20, $blue); +gdImageFilledRectangle($im, 150, 10, 170, 30, $white); +gdImageRectangle( $im, 150, 10, 170, 30, $blue); + +ok gdAssertImageEqualsToFile + $*PROGRAM.sibling("ported-gdimagerectangle/gdimagerectangle0.png"), + $im +; + +# vim: expandtab shiftwidth=4 diff --git a/xt/ported-gdimagerectangle/gdimagerectangle0.png b/xt/ported-gdimagerectangle/gdimagerectangle0.png new file mode 100644 index 0000000..b230dd0 Binary files /dev/null and b/xt/ported-gdimagerectangle/gdimagerectangle0.png differ