Page 1 of 1

Setting up ImageMagick in XCode

Posted: 2009-10-15T12:50:04-07:00
by xc3ll
I got imagemagick installed and I've been able to successfully compile all of my projects via the command line, but I'd like to use XCode since it provides a lot of debugging features, which would be nice. I've tried so far to get it working, but I can't seem to get it to compile in Xcode. I have version 3.1, can anyone help me out?

I'm getting a lot of errors about the magick object calls being referenced (it seems its not finding the imagemagick libarary).

So far, I've added /opt/local/inlcude/ImageMagick in the Search Header field and /opt/local/lib in the Search Library field under the Edit Active Target window.

Thanks!

Edit:

I've made some progess by checking out the Magick++-config script and putting all the flags located in there in the C++ flags section. however, for some reason, the draw function doesn't seem to link properly. Is there a known problem with this, or known solution?

Right now, I have the draw function commented out, but it would be nice to get it to work.

Thanks!

Re: Setting up ImageMagick in XCode

Posted: 2009-10-16T12:53:18-07:00
by John.Green
Have you put the dylib into your xcode project AND set the target to link against the dylib?

Re: Setting up ImageMagick in XCode

Posted: 2010-12-29T10:06:01-07:00
by B.Ramzi
Hi !

I can't set up image magick in Xcode.

I've added /opt/local/inlcude/ImageMagick in the Search Header field and /opt/local/lib in the Search Library field also.

I'm working in C language.

I've added all of the libraries I found (libMagickCore libMagickWand libMagick++ both .a and .dylib) in my project's folder, under a Frameworks group in my project, and in the Link Binary with Library build phase under targets.
I'm working on an image, which is Imageproj.jpg. I've added it also in my project's folder, under a Resources group in my project and in the Copy Bundle Resources build phase.

Here is my program, which just opens an image and should save it under another name :

Code: Select all

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <magick/api.h>
#include <magick/ImageMagick.h>
#include <magick/MagickCore.h>

int main() {
	ExceptionInfo *exception;
	Image *image,*scaled_image;
	ImageInfo *image_info;
	
	//Initializing ImageMagick
	InitializeMagick((char *) NULL);
	exception=AcquireExceptionInfo();
	image_info=CloneImageInfo(NULL);
	
	//Reading an Image
	strcpy(image_info->filename, "Imageproj.jpg");
	image=ReadImage(image_info, exception);
	
	
	//Saving an image under another name
	strcpy(image_info->filename, "imagetr.jpg");
	WriteImage(image_info, image);
	DestroyImage(image);
	
	//Closing Image Magick
	DestroyMagick();
	
}
Here's what I get in the console :
  • [Session started at 2010-12-29 18:04:56 +0100.]
    Assertion failed: (image->signature == MagickSignature), function WriteImage, file magick/constitute.c, line 1028.

    [Session started at 2010-12-29 18:04:57 +0100.]
    Loading program into debugger…
    GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "i386-apple-darwin".
    Program loaded.
    sharedlibrary apply-load-rules all
    Attaching to program: `/Users/ramzi/Documents/Projet C New/build/Debug/Projet C New', process 2661.

    The Debugger Debugger is attaching to process
It says that the build succeded, but there is not any imagetr.jpg file created in my computer

Please help !

Re: Setting up ImageMagick in XCode

Posted: 2010-12-29T10:15:59-07:00
by magick
  • Assertion failed: (image->signature == MagickSignature), function WriteImage
You are compiling with one version of ImageMagick and linking to another. As a result you get a member offset between the two versions which causes the assertion. We compiled your code on our Linux box without complaint.

Change image_info to image in this line:
  • strcpy(image->filename, "imagetr.jpg");

Re: Setting up ImageMagick in XCode

Posted: 2010-12-29T10:26:01-07:00
by B.Ramzi
Thanks for answering !

How should I compile and link to the same version ?

It's a homework I have to do, and maybe I didn't install the same version of ImageMagick as my homework's text have been written for ..?


If make the change you said (only in the line you said), I get this in the console :

  • [Session started at 2010-12-29 18:20:58 +0100.]

    [Session started at 2010-12-29 18:20:59 +0100.]
    Loading program into debugger…
    GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "i386-apple-darwin".
    Program loaded.
    sharedlibrary apply-load-rules all
    Attaching to program: `/Users/ramzi/Documents/Projet C New/build/Debug/Projet C New', process 2878.
And after clicking continue (two times, it's the same for more) I get :
  • [Session started at 2010-12-29 18:20:59 +0100.]
    Loading program into debugger…
    GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "i386-apple-darwin".
    Program loaded.
    sharedlibrary apply-load-rules all
    Attaching to program: `/Users/ramzi/Documents/Projet C New/build/Debug/Projet C New', process 2878.
    (gdb) continue
    Program received signal: “EXC_BAD_ACCESS”.
    (gdb) continue
    Program received signal: “EXC_BAD_ACCESS”.
    (gdb)
And still no imagetr.jpg created ...

Re: Setting up ImageMagick in XCode

Posted: 2010-12-29T10:32:44-07:00
by magick
Your program is functionaly correct and we proved it by running it on our Linux box. The imagetr.jpg image was created as expected. Its possible that the image is not being read. Notice how you do not check to ensure 'image' was created. Add
  • printf("%p\n",image);
after the ReadImage() statement. If image is NULL, the image was not read properly. To find out why, print the exception. Perhaps your version of ImageMagick does not support JPEG.

Re: Setting up ImageMagick in XCode

Posted: 2010-12-29T10:42:07-07:00
by B.Ramzi
It doesn't print NULL but 0x0

I'm sorry but I don't know how to print exception ...

With :

printf("%s\n",exception);

I get :

  • [Session started at 2010-12-29 18:39:14 +0100.]
    Loading program into debugger…
    GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "i386-apple-darwin".
    tty /dev/ttys001
    Program loaded.
    sharedlibrary apply-load-rules all
    run
    [Switching to process 3156 local thread 0x2d03]
    Running…
    0x0
    \263
    Program received signal: “EXC_BAD_ACCESS”.
    (gdb)

On school's computers (running on windows with visualc++ 2008) when we were getting started, we frequently encountered that problem of the image not being read. But it was resolved by placing the image's file in the project's folder.
Maybe it's just that xcode can't find the file ? And I just didn't add it properly as a "resource" or something ..?

Re: Setting up ImageMagick in XCode

Posted: 2010-12-29T10:50:32-07:00
by magick
0x0 is NULL. It simply means, ImageMagick could not find your image file.

Take a look at the sample MagickCore program @ http://www.imagemagick.org/script/magick-core.php. It shows one way to catch and display exceptions.

Re: Setting up ImageMagick in XCode

Posted: 2010-12-29T11:25:18-07:00
by B.Ramzi
I didn't find out how to display exception ... But I tried with a bmp and it's totally the same.

I'd like to know how does image magick, inside Xcode, seeks for files. I mean when you give him just a file name, without any path, in which path does he search for a file with the file name you specified ?
Or how to make sure that the file I'm working on is properly added to my Xcode project, and Image Magick commands would find it for sure ?

Re: Setting up ImageMagick in XCode

Posted: 2010-12-29T11:30:08-07:00
by B.Ramzi
Haaa it works !
I just specified the path rather than juste image.bmp and it worked and created the new file !


Thank you very much !!