问题
I'm generating a barcode with PEAR::Image_Barcode which uses GD, but I need to write that barcode onto a section of a PDF and PHP/Imagick seems to be the easiest way to do that, is there any way to convert a GD image object into something Imagick can work with?
回答1:
here we go:
ob_start();
Image_Barcode::draw($barcode, 'upca', 'gif');
$couponBarcode = ob_get_contents();
ob_end_clean();
$second = new Imagick();
$second->readImageBlob($couponBarcode)
it's writing the image to an output buffer with GD then reading that variable into an Imagick object
回答2:
ImageMagick has internal image creation functions. Using a barcode font you can directly create barcodes in ImageMagick. I guess ImageMagick will be more efficient in building images than PHP. Not sure about this (imageimagick's PDF functions are some times unexpected) but, as an additional bonus you may end up with vector output instead of bitmap, which will take more space and will not scale well.
来源:https://stackoverflow.com/questions/6298075/pass-gd-image-object-to-imagick