WebFaction
Community site: login faq

I installed ImageMagick on my server to use with CodeIgniter. The install showed no errors, however I can't seem to get it working at all. Here's an example of a function that tries to use imagemagick:

function image_thumb($graphic_filename, $width, $height, $ratio = TRUE) {
    // Get the CodeIgniter super object
    $CI =& get_instance();

    $image_path = '/home/lfc1450/webapps/lfcfrontend/images/message_images/' . $graphic_filename;
    $cached_path = '/home/lfc1450/webapps/lfcfrontend/images/cached/' . $graphic_filename;
    $url_path = '/images/cached/'.$graphic_filename;

    if( ! file_exists($cached_path)) {
        // Load the library
        $CI->load->library('image_lib');

        // Configure the image library
        $config['image_library'] = 'imagemagick';
        $config['library_path'] = '~/bin';
        $config['source_image'] = $image_path;
        $config['new_image'] = $cached_path;
        $config['maintain_ratio'] = $ratio;
        $config['width'] = $width;
        $config['height'] = $height;
        $CI->image_lib->initialize($config);

        if ( ! $CI->image_lib->resize())
        {
            echo $CI->image_lib->display_errors();
            $CI->image_lib->clear();
        }
    }

    return $url_path;

}

I'm getting the expected output from the code, but it's not creating the image. Is there anything obviously wrong with the code below (besides not being super-flexible yet, I'm just trying to get it working)? I'd be open to using GD, but merely choosing that as the image library hasn't worked either.

Thanks in advance for any help you guys can provide.

asked 20 Oct '10, 09:29

davidhemphill
324
accept rate: 0%

I don't know much about CI, but after reviewing the Image Manipulation Class docs I think your code looks OK. Here are a couple of things you could try:

  • Remove the $cached_path condition just to rule out any problems with that
  • Try using /home/lfc1450/bin instead of ~/bin for the library path.

Also, while looking into this I noticed that you've set 777 permissions on a few directories. That's not going to solve this problem, and it's very insecure, so you should tighten that up ASAP.

(20 Oct '10, 15:49) seanf

Hey Sean. I tried your suggestions (and tightened up the permissions), but I still can't get it working. I posted on the codeigniter forum, but have yet to get any response.

Thanks for trying!

(20 Oct '10, 21:25) davidhemphill

I noticed this little snippet in the documentation:

Note: In addition, even though other libraries are supported, GD is required in order for the script to calculate the image properties. The image processing, however, will be performed with the library you specify.

Would that have anything to do with my troubles getting this working?

(20 Oct '10, 21:33) davidhemphill

GD is already installed on our servers, so this shouldn't be a problem.

Are you able to use ImageMagick outside of CodeIgniter without issues?

(21 Oct '10, 02:47) David L ♦♦

I am able to use ImageMagick outside of CodeIgniter. I copied and image directly into the bin folder and it converted a jpg to png with no problem.

I should as an alternative be able to use GD to do the resizing, but that hasn't worked either. So I'm guessing the library just plain isn't working at all.

(22 Oct '10, 12:07) davidhemphill

The answer turned out to be that I was using the in-development 2.0 version of CodeIgniter instead of the stable 1.7 branch. I can now use GD2 and ImageMagick to do the resizing.

Thanks for the help. Sorry to be a pain in the butt.

(22 Oct '10, 12:24) davidhemphill

No problem, glad you were able to get it working!

(23 Oct '10, 15:11) seanf
showing 5 of 7 show 2 more comments

From the comments:

The answer turned out to be that I was using the in-development 2.0 version of CodeIgniter instead of the stable 1.7 branch. I can now use GD2 and ImageMagick to do the resizing.

permanent link

answered 23 Oct '10, 15:11

seanf
12.2k41836
accept rate: 37%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×262
×11
×4

question asked: 20 Oct '10, 09:29

question was seen: 6,208 times

last updated: 23 Oct '10, 15:11

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM