MopaBarcodeBundle icon indicating copy to clipboard operation
MopaBarcodeBundle copied to clipboard

issue in generating multiple barcode images

Open ankitchauhan22 opened this issue 12 years ago • 6 comments

Hi I am trying to generate multiple barcode image files by looping loop start...... $barcodeService = $this->container->get('mopa_barcode.barcode_service'); $filename = $barcode . ".png"; $barcodeService->saveAs('code128', $barcode, $filename); loop end here.....

for one item its working fine but when trying it in looping it giving me an exception as ErrorException: Warning: imagesy(): 57 is not a valid Image resource in /vendor/Zend/library/Zend/Barcode/Renderer/Image.php line 267

Can you please help me out?

ankitchauhan22 avatar Sep 19 '12 12:09 ankitchauhan22

I had the same issue. The issue was actually with Zend - not with this bundle, particularly the use of the registry (singleton) pattern for the management of objects.

edit: what version of ZF2 are you using? My branch only works with version 2.0.0-beta4. I've had a quick look over the latest code, and while the names of the methods have changed - the issue still looks as if it will be there.

I ended up forking the Zend Barcode bundle and using that instead of the official zend bundle as I was pressed for time. I intend to participate in the zend bundle at some stage.

Take a look at the 'fix' i made: https://github.com/calumbrodie/zend-barcode/tree/mopa_compatible

Commits: https://github.com/calumbrodie/zend-barcode/commit/28d6578bfe8b5e3141d53fe4972a4f8d7ade9e28 and https://github.com/calumbrodie/zend-barcode/commit/d270620e18ce998fe30c0765e07db815b38fe57d

And see how that compares to the same file from the latest version.

calumbrodie avatar Oct 24 '12 17:10 calumbrodie

I'm using Symfony 2.0.17 and i did get same error - in my case temporarily change to ZF framework to release-2.0.0beta1 helped.

tomaszozga avatar Oct 31 '12 12:10 tomaszozga

k what do we need to fix this permanently?

phiamo avatar Feb 19 '13 13:02 phiamo

pinging @shieldo who fixed this issue in our codebase.

calumbrodie avatar Feb 19 '13 13:02 calumbrodie

Hi folks!

As @calumbrodie pointed out, the problem here seems to be ZF's use of the registry pattern/ storing generated barcodes within the factory object.

I have managed to work around this limitation by temporarily setting the plugin manager as to not share objects by default, so that a new barcode object is generated instead of the old one being returned.

Here's some code I'm using to give you an idea:

        $renderer = new ImageRenderer($rendererConfig);
        //make sure Zend object plugin manager does not share created barcode object
        $objectPluginManager = Barcode::getObjectPluginManager();
        $originallySharedByDefault = $objectPluginManager->shareByDefault();
        if ($originallySharedByDefault) {
            $objectPluginManager->setShareByDefault(false);
        }
        $barcodeObject = $objectPluginManager->get($barcode, $barcodeConfig);
        if ($originallySharedByDefault) {
            //reset object plugin manager
            $objectPluginManager->setShareByDefault(true);
        }
        $renderer->setBarcode($barcodeObject);

shieldo avatar Feb 19 '13 14:02 shieldo

can you make a PR please

phiamo avatar Apr 10 '13 23:04 phiamo