Giter VIP home page Giter VIP logo

gmagick's Introduction

Gmagick

Copyright (c) 2009 Vito Chin, Mikko Koppanen

PHP extension that wraps the GraphicsMagick library. Access GraphicsMagick's capabilities via PHP.

Build Status

Getting Started

  1. Install GraphicsMagick

Download the stable from from http://www.graphicsmagick.org and build with --enable-shared option. If you do not need to work with perl, --without-perl.

Remember to run ldconfig after building GraphicsMagick to update shared library cache for immediate use.

  1. Install Gmagick

Typically, as with most extensions:

$ phpize
$ ./configure
$ make
$ make install

Functions not supported

The functions listed below are deliberately not part of the Gmagick extension. Other functions that are present in the GraphicsMagick library but not exposed by Gmagick are likely to be added in the future.

MagickAnimateImages - only useful with X terminals. MagickDisplayImage - only useful with X terminals. MagickDisplayImages - only useful with X terminals. MagickGetConfigureInfo - not implemented in GraphicsMagick MagickFxImage - not implemented in GraphicsMagick MagickFxImageChannel - not implemented in GraphicsMagick MagickGetImageSize - just get the image a string and do strlen MagickPreviewImages - not implemented in GraphicsMagick MagickSetPassphrase - use real encryption if you need to protect data MagickTintImage - not implemented in GraphicsMagick MagickTransformImage - this is a 'helper' function which duplicates other easier to use functions.

gmagick's People

Contributors

asgrim avatar benmorel avatar brokentone avatar danack avatar jecknig avatar lentor-deploy avatar remicollet avatar rlerdorf avatar vitoc avatar vyran avatar wcgallego avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gmagick's Issues

How to make gifs?

Can you explain what is wrong with the code below. I would expect it to make a gif, instead it gives an error of: Fatal error: Uncaught GmagickException: Can not process empty Gmagick object in /home/github/graphicsmagick/gmagick/test.php:25

$canvas = new Gmagick();

$colors = array(
    'red',
    'white',
    'blue',
    'yellow',
    'black',
);

foreach ($colors as $color) {
    $image = new Gmagick();
    $image->newimage (500, 500, $color);
    //$image->setImageFormat("PNG");
    //$image->writeImage("./test_$color.png");
    $canvas->addImage($image);
}

$canvas->setImageFormat("PNG");
$canvas->writeImages("./output.gif");

PHP 7.1 build

Build is ok, but trying to load the extension raise a fatal error.

 PHP Fatal error:  Cannot redefine class constant Gmagick::INTERLACE_LINE in Unknown on line 0

FYI: same issue affects "crypto", fixed in bukka/php-crypto@ee493a2

MacOS Yosemite PHP 5.6.2/5.6.3: error for object 0x1047f21f0: pointer being freed was not allocated

When I install php-gmagick using brew to be used on my MacOS Yosemite 10.10, I got the following error message with php-gmagick enabled:

Fractal:conf.d admin$ php -v
php(12688,0x7fff7a504300) malloc: *** error for object 0x1047f21f0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

Installed with

brew install php56
brew install php56-gmagick php56-mcrypt  php56-pdo-pgsql php56-xdebug

If I remove php-gmagick, all is ok.

Different widths?

Hi, I encountered a strange problem, after scale image:
1、gm cli and pgmagick(python):
>> gm convert a.jpg -scale 374x269 a_374x269.jpg
>> im.scale('374x269')
Result: image a_374x269.jpg is 359x269
2、gmagick:
>> $image->scaleimage(374, 269, true)
Result: image a_374x269.jpg is 358x269

Thank you!

Failed test gmagick-117_haldClutImage_basic.php

 Fatal error: Uncaught GmagickException: Unable to open file (/dev/shm/BUILD/php70-php-pecl-gmagick-2.0.1/NTS/tests/hald_8.png) in /dev/shm/BUILD/php70-php-pecl-gmagick-2.0.1/NTS/tests/gmagick-117_haldClutImage_basic.php:6
 Stack trace:
 #0 /dev/shm/BUILD/php70-php-pecl-gmagick-2.0.1/NTS/tests/gmagick-117_haldClutImage_basic.php(6): Gmagick->__construct('/dev/shm/BUILD/...')
 #1 /dev/shm/BUILD/php70-php-pecl-gmagick-2.0.1/NTS/tests/gmagick-117_haldClutImage_basic.php(14): haldClutImage()
 #2 {main}

Trivial fix, please add the image to package.xml

setresolution is missing

Gmagick doesn't yet have an analogue of Imagick's setResolution function. Are there plans for adding it? I could contribute it myself, if this would help.

coalesceImages doesn't work properly with some animated gifs

Hi,

I encountered a bug in coalesceImages with some animated gifs. No problem with Imagick.

Here is my test code:

$image = new Gmagick();
$image->readImageBlob($object->getData());
if($image->getNumberImages() > 1){
    $image = $image->coalesceImages();
    do {
        $frame = $image->current();
        $frame->cropThumbnailImage($width, $height);
        $frame->setCompressionQuality(85);
    }while($image->nextImage());
    $image = $image->deconstructimages();

}else{
    $image->cropThumbnailImage($width, $height);
    $image->setCompressionQuality(85);
}
echo $image->getImagesBlob();

And here is an image for test:
Image
(sorry, I randomly picked an image from a blog)

If I try to crop it with $width=400 and $height=400:
Image 400x400

Adding missing methods

The methods below are missing, I'm going to post these here, with some instructions for someone who wants to contribute to follow.

DrawingWand:
Missing: CloneDrawingWand
Missing: DrawClearException
Missing: DrawGetException
Missing: DrawMatte
Missing: DrawPeekGraphicContext
Missing: DrawRender
Missing: DrawSetStopColor

PixelWand:
Missing: ClonePixelWand
Missing: ClonePixelWands

Missing: PixelGetBlackQuantum
Missing: PixelGetBlueQuantum
Missing: PixelGetCyanQuantum
Missing: PixelGetGreenQuantum
Missing: PixelGetMagentaQuantum
Missing: PixelGetOpacityQuantum
Missing: PixelGetRedQuantum
Missing: PixelGetYellowQuantum
Missing: PixelSetBlackQuantum
Missing: PixelSetBlueQuantum
Missing: PixelSetColorCount
Missing: PixelSetCyanQuantum
Missing: PixelSetGreenQuantum
Missing: PixelSetMagentaQuantum
Missing: PixelSetOpacityQuantum
Missing: PixelSetQuantumColor
Missing: PixelSetRedQuantum
Missing: PixelSetYellowQuantum

Missing: MagickAnimateImages
Missing: MagickDescribeImage
Missing: MagickGetImagePixels
Missing: MagickOpaqueImage
Missing: MagickPingImage
Missing: MagickSetImagePixels
Missing: MagickTransparentImage

OpenMP support

Hi,

I've noticed that all my Gmagick code runs on a single CPU core, which is a pity on servers with 8 cores or more, given that GraphicsMagick supports OpenMP.

Is there a reason for this? Imagick leaves the choice to enable OpenMP, can we do the same for Gmagick?

Missing git tags

There are no tags in this git repository. I expected to see a tag for each version of this project that has been released.

gmagick coredump

(gdb) bt
#0 0x00007f9985fd15c9 in raise () from /lib64/libc.so.6
#1 0x00007f9985fd2e18 in abort () from /lib64/libc.so.6
#2 0x00007f997a867338 in MagickPanicSignalHandler () from /usr/local/GraphicsMagick/lib/libGraphicsMagick.so.3
#3
#4 0x0000000000834538 in zend_std_object_get_class (object=0x35ab470) at /home/work/env/php/php-5.6.15/Zend/zend_object_handlers.c:1528
#5 0x0000000000859533 in ZEND_INIT_METHOD_CALL_SPEC_VAR_CONST_HANDLER (execute_data=0x7f99894c8940)

at /home/work/env/php/php-5.6.15/Zend/zend_vm_execute.h:15736

#6 0x0000000000844808 in execute_ex (execute_data=0x7f99894c8940) at /home/work/env/php/php-5.6.15/Zend/zend_vm_execute.h:363
#7 0x00000000007ff9d3 in zend_call_function (fci=fci@entry=0x7fff0e0b87e0, fci_cache=, fci_cache@entry=0x7fff0e0b87b0)

at /home/work/env/php/php-5.6.15/Zend/zend_execute_API.c:829

#8 0x0000000000825b45 in zend_call_method (object_pp=object_pp@entry=0x7fff0e0b8898, obj_ce=,

fn_proxy=fn_proxy@entry=0x7fff0e0b8890, function_name=function_name@entry=0xac6b0d "__destruct", 
function_name_len=function_name_len@entry=10, retval_ptr_ptr=retval_ptr_ptr@entry=0x0, param_count=param_count@entry=0, 
arg1=arg1@entry=0x0, arg2=arg2@entry=0x0) at /home/work/env/php/php-5.6.15/Zend/zend_interfaces.c:97

#9 0x00000000008340a2 in zend_objects_destroy_object (object=0x35a6840, handle=)

at /home/work/env/php/php-5.6.15/Zend/zend_objects.c:123

#10 0x000000000082dd46 in gc_collect_cycles () at /home/work/env/php/php-5.6.15/Zend/zend_gc.c:811
#11 0x000000000082e292 in gc_zval_possible_root (zv=zv@entry=0x6e8a638) at /home/work/env/php/php-5.6.15/Zend/zend_gc.c:163
#12 0x00000000008b409e in gc_zval_check_possible_root (z=0x6e8a638) at /home/work/env/php/php-5.6.15/Zend/zend_gc.h:183
#13 i_zval_ptr_dtor (zval_ptr=0x6e8a638) at /home/work/env/php/php-5.6.15/Zend/zend_execute.h:86
#14 zend_vm_stack_clear_multiple (nested=0) at /home/work/env/php/php-5.6.15/Zend/zend_execute.h:308
#15 zend_do_fcall_common_helper_SPEC (execute_data=) at /home/work/env/php/php-5.6.15/Zend/zend_vm_execute.h:650
#16 0x0000000000844808 in execute_ex (execute_data=0x7f99894c87e8) at /home/work/env/php/php-5.6.15/Zend/zend_vm_execute.h:363
#17 0x00000000007ff9d3 in zend_call_function (fci=fci@entry=0x7fff0e0b8c60, fci_cache=, fci_cache@entry=0x7fff0e0b8c30)

at /home/work/env/php/php-5.6.15/Zend/zend_execute_API.c:829

#18 0x0000000000825b45 in zend_call_method (object_pp=object_pp@entry=0x7fff0e0b8d10, obj_ce=, obj_ce@entry=0x301d5c8,

fn_proxy=fn_proxy@entry=0x301d720, function_name=function_name@entry=0xace193 "__call", function_name_len=function_name_len@entry=6, 
retval_ptr_ptr=retval_ptr_ptr@entry=0x7fff0e0b8d38, param_count=param_count@entry=2, arg1=arg1@entry=0x6ce3250, arg2=0x6ce3de8)
at /home/work/env/php/php-5.6.15/Zend/zend_interfaces.c:97

#19 0x000000000083504c in zend_std_call_user_call (ht=, return_value=0x6cc4150, return_value_ptr=0x7f99894c7e80,

this_ptr=0x6ce99d0, return_value_used=<optimized out>) at /home/work/env/php/php-5.6.15/Zend/zend_object_handlers.c:931

#20 0x00000000008b3f74 in zend_do_fcall_common_helper_SPEC (execute_data=)

at /home/work/env/php/php-5.6.15/Zend/zend_vm_execute.h:560

#21 0x0000000000844808 in execute_ex (execute_data=0x7f99894c7e98) at /home/work/env/php/php-5.6.15/Zend/zend_vm_execute.h:363
#22 0x00000000007ff9d3 in zend_call_function (fci=fci@entry=0x7fff0e0b9000, fci_cache=, fci_cache@entry=0x7fff0e0b8fd0)

at /home/work/env/php/php-5.6.15/Zend/zend_execute_API.c:829

#23 0x0000000000705532 in zif_call_user_func_array (ht=, return_value=0x510e8c0, return_value_ptr=,

this_ptr=<optimized out>, return_value_used=<optimized out>) at /home/work/env/php/php-5.6.15/ext/standard/basic_functions.c:4784

---Type to continue, or q to quit---
#24 0x00000000008b3f74 in zend_do_fcall_common_helper_SPEC (execute_data=)

at /home/work/env/php/php-5.6.15/Zend/zend_vm_execute.h:560

#25 0x0000000000844808 in execute_ex (execute_data=0x7f99894c7678) at /home/work/env/php/php-5.6.15/Zend/zend_vm_execute.h:363
#26 0x00000000007ff9d3 in zend_call_function (fci=fci@entry=0x7fff0e0b92c0, fci_cache=, fci_cache@entry=0x0)

at /home/work/env/php/php-5.6.15/Zend/zend_execute_API.c:829

#27 0x00000000007ffbbe in call_user_function_ex (function_table=, object_pp=object_pp@entry=0x0,

function_name=<optimized out>, retval_ptr_ptr=retval_ptr_ptr@entry=0x7fff0e0b9370, param_count=param_count@entry=4, 
params=params@entry=0x7fff0e0b9380, no_separation=no_separation@entry=0, symbol_table=symbol_table@entry=0x0)
at /home/work/env/php/php-5.6.15/Zend/zend_execute_API.c:617

#28 0x00007f997af60aaf in php_swoole_onTask (serv=0x2d1f890, req=)

at /home/work/env/php/extensions/swoole-src-git/swoole_server.c:668

#29 0x00007f997af88878 in swProcessPool_worker_loop (pool=0x7f997a31d1c0, worker=0x7f997a31ea80)

at /home/work/env/php/extensions/swoole-src-git/src/network/ProcessPool.c:327

#30 0x00007f997af891f8 in swProcessPool_spawn (worker=0x7f997a31ea80)

at /home/work/env/php/extensions/swoole-src-git/src/network/ProcessPool.c:234

#31 0x00007f997af89321 in swProcessPool_start (pool=0x7f997a31d1c0)

at /home/work/env/php/extensions/swoole-src-git/src/network/ProcessPool.c:106

#32 0x00007f997af8f290 in swManager_start (factory=factory@entry=0x2d1fdc0)

at /home/work/env/php/extensions/swoole-src-git/src/network/Manager.c:138

#33 0x00007f997af7eff4 in swFactoryProcess_start (factory=0x2d1fdc0)

at /home/work/env/php/extensions/swoole-src-git/src/factory/FactoryProcess.c:86

#34 0x00007f997af85c2d in swServer_start (serv=serv@entry=0x2d1f890) at /home/work/env/php/extensions/swoole-src-git/src/network/Server.c:586
#35 0x00007f997af635b0 in zif_swoole_server_start (ht=, return_value=0x2fd1e18, return_value_ptr=,

this_ptr=<optimized out>, return_value_used=<optimized out>) at /home/work/env/php/extensions/swoole-src-git/swoole_server.c:1997

#36 0x00000000008b3f74 in zend_do_fcall_common_helper_SPEC (execute_data=)

at /home/work/env/php/php-5.6.15/Zend/zend_vm_execute.h:560

#37 0x0000000000844808 in execute_ex (execute_data=0x7f99894c7410) at /home/work/env/php/php-5.6.15/Zend/zend_vm_execute.h:363
#38 0x00000000008103b0 in zend_execute_scripts (type=type@entry=8, retval=retval@entry=0x0, file_count=file_count@entry=3)

at /home/work/env/php/php-5.6.15/Zend/zend.c:1341

#39 0x00000000007ae9a2 in php_execute_script (primary_file=primary_file@entry=0x7fff0e0bdbd0)

at /home/work/env/php/php-5.6.15/main/main.c:2597

#40 0x00000000008b5f21 in do_cli (argc=6, argv=0x2a34bf0) at /home/work/env/php/php-5.6.15/sapi/cli/php_cli.c:994
#41 0x0000000000435bef in main (argc=6, argv=0x2a34bf0) at /home/work/env/php/php-5.6.15/sapi/cli/php_cli.c:1378

Failed test gmagick-104-setgetimagepage

 Fatal error: Uncaught Error: Call to undefined method Gmagick::setImagePage() in /dev/shm/BUILD/php70-php-pecl-gmagick-2.0.1/NTS/tests/gmagick-104-setgetimagepage.php:3
 Stack trace:
 #0 {main}
   thrown in /dev/shm/BUILD/php70-php-pecl-gmagick-2.0.1/NTS/tests/gmagick-104-setgetimagepage.php on line 3

IF the method doesn"t exists the test should probably be skiped, but looking at the code, I don't understand where the GMAGICK_HAVE_SET_IMAGE_PAGE comes from.

With GraphicsMagick-1.3.23 (Fedora 23), this fonction exists

$ grep -r MagickSetImagePage /usr/include/GraphicsMagick/
/usr/include/GraphicsMagick/wand/wand_symbols.h:#define MagickSetImagePage GmMagickSetImagePage
/usr/include/GraphicsMagick/wand/magick_wand.h:  MagickSetImagePage(MagickWand *wand,

Probably detection missing in config.m4 (seems related to 79f1690)

php: symbol lookup error: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/gmagick.so: undefined symbol: omp_get_num_procs

php: symbol lookup error: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/gmagick.so: undefined symbol: omp_get_num_procs

[work@dd ~/env/php/extensions/gmagick/gmagick-1.1.7RC3]$ php-config
Usage: /usr/local/php/bin/php-config [OPTION]
Options:
--prefix [/usr/local/php]
--includes [-I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib]
--ldflags []
--libs [-lcrypt -lz -lresolv -lcrypt -lreadline -lncurses -lrt -lmcrypt -lpng -lz -ljpeg -lcurl -lbz2 -lz -lrt -lm -ldl -lnsl -lxml2 -lz -lm -ldl -lssl -lcrypto -lcurl -lxml2 -lz -lm -ldl -lssl -lcrypto -lfreetype -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lssl -lcrypto -lcrypt ]
--extension-dir [/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226]
--include-dir [/usr/local/php/include/php]
--man-dir [/usr/local/php/php/man]
--php-binary [/usr/local/php/bin/php]
--php-sapis [ cli fpm cgi]
--configure-options [--prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc/ --with-fpm-user=www --with-fpm-group=www --enable-opcache --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd --disable-fileinfo --with-freetype-dir --with-jpeg-dir --with-png-dir --with-gd --enable-gd-native-ttf --with-zlib --with-zlib-dir --with-mcrypt --enable-shmop --enable-sockets --enable-wddx --enable-fpm --enable-mbstring --with-bz2 --enable-exif --enable-ftp --with-iconv --with-iconv-dir=/usr/local --with-libxml-dir=/usr/include/libxml2 --enable-xml --enable-bcmath --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --with-openssl --with-mhash --enable-pcntl --with-xmlrpc --with-gettext --with-readline --enable-zip --enable-soap --enable-ipv6 --enable-session]
--version [5.6.10]
--vernum [50610]

Add support for setTextAlignment()

ImagickDraw provides the above function to set the alignment of text when annotating an image. Please add the same functionality to Gmagick so that images can be annotated with multiple lines of right-justified text.

white background with SVG image

Hi folks,
I was testing out a watermark function, and while it works great with PNG images, my SVG image is being added with a lovely white background.
Is there any way to get the Gmagick extension to properly handle SVG images and transparency?

Here is essentially my code (commented bits are things I've tried to make this work):

$image = new Gmagick( '/path/to/my-image.jpg' );
...
$watermark          = new Gmagick();
// $watermark_contents = file_get_contents( $this->watermark );
//                      $watermark->newimage( round( $this->image_width * .15 ), round( $this->image_height * .15 ), 'none', 'png' );
//                      $watermark->setimagebackgroundcolor( new GmagickPixel( 'transparent' ) );
//                              $watermark->setimagecolorspace( Gmagick::COLORSPACE_TRANSPARENT );
//              $watermark->readimageblob( $watermark_contents );
$watermark->readimage( '/path/to/my-watermark.svg );
$image->compositeimage( $watermark, 1, $pos_x, $pos_y );

Any thoughts/ideas? Is it not possible with Gmagick?
My source/test image is here: https://test.exactlywww.com/wp-content/uploads/2021/03/LB-ZCAV-1A22.jpg
SVG watermark here: https://test.exactlywww.com/wp-content/uploads/2022/08/ewwwio-logo-gray.svg (I was originally using a white version, but the gray color helps to see better what is happening.

GMagick fails to render Google Fonts in SVG

My Ubuntu 14.04 laptop has GraphicsMagick and the PHP extension (GMagick) installed. When I run the following from the command line,

gm convert -font /usr/share/fonts/truetype/google-fonts/RockSalt.ttf svg_file.svg jpeg_file.jpg

renders the JPEG with the font as desired. However, this PHP code

$gm = new Gmagick();
$draw = new GmagickDraw();
$draw->setfont("/usr/share/fonts/truetype/google-fonts/RockSalt.ttf");
$gm->readImageBlob($svg);
$gm->setImageFormat("jpeg");
$gm->drawimage($draw);
$gm->writeImage($jpgFile);
$gm->clear();
Fails to do the same and creates a JPEG with a default font. What could be the issue here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.