Can't write png file

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
clhsieh
Posts: 12
Joined: 2012-10-24T00:03:11-07:00
Authentication code: 67789

Can't write png file

Post by clhsieh »

As title, I can't write png file using Magick++, other format like jpg, gif are all right.
But the convert or mogrify can correctly deal with png.

My code for test is extremely easy.

Code: Select all

#include <Magick++.h>

using namespace Magick;

int main(int argc, char* argv[])
{
    InitializeMagick(*argv);
    Image image("logo.dpx");
    image.write("logo.png");
    return 0;
}
The logo.dpx can be get using

Code: Select all

convert logo: -alpha off -depth 10 logo.dpx
The error message is

Code: Select all

terminate called after throwing an instance of 'Magick::ErrorResourceLimit'
  what():  ImageMagick: memory allocation failed `logo.png' @ error/png.c/WriteOnePNGImage/8982
Aborted
I use ImageMagick-6.7.9-6 build from source using below configuration

Code: Select all

                  Option                        Value
-------------------------------------------------------------------------------
Shared libraries  --enable-shared=yes		yes
Static libraries  --enable-static=yes		yes
Module support    --with-modules=no		no
GNU ld            --with-gnu-ld=yes		yes
Quantum depth     --with-quantum-depth=16	16
High Dynamic Range Imagery
                  --enable-hdri=no		no

Delegate Configuration:
BZLIB             --with-bzlib=yes		yes
Autotrace         --with-autotrace=no		no
Dejavu fonts      --with-dejavu-font-dir=default	none
DJVU              --with-djvu=yes		no
DPS               --with-dps=yes		no
FFTW              --with-fftw=yes		yes
FlashPIX          --with-fpx=yes		no
FontConfig        --with-fontconfig=yes		no
FreeType          --with-freetype=yes		yes
GhostPCL          None				pcl6 (unknown)
GhostXPS          None				gxps (unknown)
Ghostscript       None				gs (8.71)
Ghostscript fonts --with-gs-font-dir=default	/usr/share/fonts/type1/gsfonts/
Ghostscript lib   --with-gslib=no		no
Graphviz          --with-gvc=no		
JBIG              --with-jbig=yes		no
JPEG v1           --with-jpeg=yes		yes
JPEG-2000         --with-jp2=yes		no
LCMS v1           --with-lcms=yes		no
LCMS v2           --with-lcms2=yes		no
LQR               --with-lqr=yes		no
LZMA              --with-lzma=yes		no
Magick++          --with-magick-plus-plus=yes	yes
OpenEXR           --with-openexr=yes		yes
PERL              --with-perl=no		no
PANGO             --with-pango=yes		no
PNG               --with-png=yes		yes
RSVG              --with-rsvg=no		no
TIFF              --with-tiff=yes		yes
WEBP              --with-webp=yes		no
Windows fonts     --with-windows-font-dir=	none
WMF               --with-wmf=no		no
X11               --with-x=			yes
XML               --with-xml=yes		no
ZLIB              --with-zlib=yes		yes

X11 Configuration:
      X_CFLAGS        = 
      X_PRE_LIBS      = -lSM -lICE
      X_LIBS          = 
      X_EXTRA_LIBS    = 

Options used to compile and link:
  PREFIX          = /usr/local
  EXEC-PREFIX     = /usr/local
  VERSION         = 6.7.9
  CC              = gcc -std=gnu99 -std=gnu99
  CFLAGS          = -pthread -I/usr/include/OpenEXR -fopenmp -g -O2 -Wall -pthread
  CPPFLAGS        = -I/usr/local/include/ImageMagick
  PCFLAGS         = -fopenmp
  DEFS            = -DHAVE_CONFIG_H
  LDFLAGS         = -L/usr/lib
  MAGICK_LDFLAGS  = -L/usr/local/lib -L/usr/lib
  LIBS            = -lMagickCore -ltiff -lfreetype -ljpeg -lpng12 -lfftw3 -lXext -lXt -lSM -lICE -lX11 -lbz2 -pthread -lIlmImf -lz -lImath -lHalf -lIex -lIlmThread -lz -lm -lgomp -lpthread 
  CXX             = g++
  CXXFLAGS        = -g -O2 -pthread
  FEATURES        = OpenMP 
Please let me know if you need any other information to help solve this problem
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can't write png file

Post by fmw42 »

in a terminal, type

convert -list configure

see if png is listed in the line starting with DELEGATES
clhsieh
Posts: 12
Joined: 2012-10-24T00:03:11-07:00
Authentication code: 67789

Re: Can't write png file

Post by clhsieh »

Yes it is
DELEGATES bzlib fftw freetype jpeg jng mpeg openexr png tiff x11 zlib
amay82
Posts: 2
Joined: 2012-10-29T08:03:23-07:00
Authentication code: 67789

Re: Can't write png file

Post by amay82 »

Have exactly the same problem with the same message.

Using FreeBSD 8.3, png-1.5.12, ImageMagick-nox11-6.7.9-4 with this configuration:

Code: Select all

Host system type: amd64-portbld-freebsd8.3
Build system type: amd64-portbld-freebsd8.3

                  Option                        Value
-------------------------------------------------------------------------------
Shared libraries  --enable-shared=yes		yes
Static libraries  --enable-static=yes		yes
Module support    --with-modules=no		no
GNU ld            --with-gnu-ld=yes		yes
Quantum depth     --with-quantum-depth=8	8
High Dynamic Range Imagery
                  --enable-hdri=no		no

Delegate Configuration:
BZLIB             --with-bzlib=yes		yes
Autotrace         --with-autotrace=no		no
Dejavu fonts      --with-dejavu-font-dir=default	none
DJVU              --with-djvu=no		no
DPS               --with-dps=no		no
FFTW              --with-fftw=yes		yes
FlashPIX          --with-fpx=no		no
FontConfig        --with-fontconfig=yes		yes
FreeType          --with-freetype=yes		yes
GhostPCL          None				pcl6 (unknown)
GhostXPS          None				gxps (unknown)
Ghostscript       None				gs (9.06)
Ghostscript fonts --with-gs-font-dir=default	/usr/local/share/ghostscript/fonts/
Ghostscript lib   --with-gslib=yes		yes
Graphviz          --with-gvc=no		
JBIG              --with-jbig=no		no
JPEG v1           --with-jpeg=yes		yes
JPEG-2000         --with-jp2=no		no
LCMS v1           --with-lcms=no		no
LCMS v2           --with-lcms2=yes		yes
LQR               --with-lqr=no		no
LZMA              --with-lzma=yes		no
Magick++          --with-magick-plus-plus=yes	yes
OpenEXR           --with-openexr=no		no
PERL              --with-perl=no		no
PANGO             --with-pango=no		no
PNG               --with-png=yes		yes
RSVG              --with-rsvg=no		no
TIFF              --with-tiff=yes		yes
WEBP              --with-webp=yes		yes
Windows fonts     --with-windows-font-dir=	none
WMF               --with-wmf=no		no
X11               --with-x=no			no
XML               --with-xml=no		no
ZLIB              --with-zlib=yes		yes

X11 Configuration:
      X_CFLAGS        = 
      X_PRE_LIBS      = 
      X_LIBS          = 
      X_EXTRA_LIBS    = 

Options used to compile and link:
  PREFIX          = /usr/local
  EXEC-PREFIX     = /usr/local
  VERSION         = 6.7.9
  CC              = cc -std=gnu99 -std=gnu99
  CFLAGS          = -O2 -fno-strict-aliasing -pipe -march=native -Wall
  CPPFLAGS        = -I/usr/local/include/ImageMagick
  PCFLAGS         = 
  DEFS            = -DHAVE_CONFIG_H
  LDFLAGS         = -L/usr/local/lib -L/usr/local/lib
  MAGICK_LDFLAGS  = -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib
  LIBS            = -lMagickCore -llcms2 -ltiff -lfreetype -ljpeg -lgs -lpng15 -lfftw3 -L/usr/local/lib -lfontconfig -lwebp -lbz2 -lz -lm -lltdl
  CXX             = c++
  CXXFLAGS        = -O2 -fno-strict-aliasing -pipe -march=native -fconserve-space
  FEATURES        = 
Everything is installed from ports. I use RMagick to create some images in my Ruby on Rails application, and RMagick uses ImageMagick (Magick++). If I try to write a simple PNG image, I get:

Code: Select all

test.rb:30:in `write': memory allocation failed `test.png' @ error/png.c/WriteOnePNGImage/8982 (Magick::ImageMagickError)
	from 1.rb:30:in `<main>'
amay82
Posts: 2
Joined: 2012-10-29T08:03:23-07:00
Authentication code: 67789

Re: Can't write png file

Post by amay82 »

Recompiling without GhostScript fixed the problem.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Can't write png file

Post by magick »

Ghostscript and PNG may have two different versions of ZLIB compiled with them or some similar problem. We compiled ImageMagick 6.8.0 with and without Ghostscript and PNG and your Magick++ code compiled and ran without complaint.
Post Reply