1

I have wrote a system for my personal website with CodeIgniter and used GD2 library to manipulate images according to my needs. It worked just fine when on localhost and a free hosting that I used for testing. But now that I am on a paid hosting from a different provider, It doesn't work for the jpg files. It shows the broken-image icon. But works just fine with PNG files. I have tried displaying the manipulation errors but nothing was displayed.

Here is my media controller, which manipulates the images;

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Media extends CI_Controller
{

function sandbox($imageName , $width)
  {

      if(!is_file('uploads/sandbox/'.$width.'-'.$imageName)) {
         $config['image_library'] = 'gd2';
         $config['source_image'] = 'uploads/original/'.$imageName;
         $config['new_image'] = 'uploads/sandbox/'.$width.'-'.$imageName;
         $config['dynamic_output'] = FALSE;
         $config['maintain_ratio'] = TRUE;
         $config['master_dim'] = 'width';
         $config['width'] = $width;
         $config['height'] = $width;

         $this->image_lib->initialize($config);
         return $this->image_lib->resize();
    }    else {
        return true;
    }

  }

  public function covers($imageName)
  {

     if($this->sandbox($imageName, 920)) {

         $config['image_library'] = 'gd2';
         $config['source_image'] = 'uploads/sandbox/'.'920-'.$imageName;
         $config['dynamic_output'] = TRUE;
         $config['maintain_ratio'] = FALSE;
         $config['width'] = 920;
         $config['height'] = 450;

         $this->image_lib->initialize($config);
         $this->image_lib->crop();

     }


  }

  public function images($imageName)
  {

     if($this->sandbox($imageName, 440)) {

         $config['image_library'] = 'gd2';
         $config['source_image'] = 'uploads/sandbox/'.'440-'.$imageName;
         $config['dynamic_output'] = TRUE;
         $config['maintain_ratio'] = FALSE;
         $config['width'] = 440;
         $config['height'] = 300;

         $this->image_lib->initialize($config);
         if(!$this->image_lib->crop()){
            echo $this->image_lib->display_errors();
         }

     }

  }

  public function facebook($imageName)
  {

     $config['image_library'] = 'gd2';
     $config['source_image'] = 'uploads/original/'.$imageName;
     $config['dynamic_output'] = TRUE;
     $config['maintain_ratio'] = FALSE;
     $config['width'] = 256;
     $config['height'] = 256;

     $this->image_lib->initialize($config);
     echo $this->image_lib->resize();

  }

}
SuperioREX
  • 257
  • 1
  • 2
  • 9
  • Have you remembered to install GD on the server? I got caught out by that once. – Matthew Daly Feb 25 '14 at 11:52
  • It's working fine while resizing and saving into another file(sandbox function above). Whether it's jpg or png. – SuperioREX Feb 25 '14 at 12:12
  • is the image_lib library autoloaded? if not then you have to load the library before you call them. I think error reporting is turned off. Try turning on the error reporting feature – Nouphal.M Feb 25 '14 at 14:23
  • Run phpinfo() on both servers and compare 'GD' section. Check for differences beetween paid and localhost/free hosting. – Robert Trzebiński Feb 25 '14 at 14:34
  • Thanks guys, I've checked that yhe library loaded. And phpinfos were the same. In the end, I changed my controller to save the images instead of serving them on the fly and it worked. – SuperioREX Feb 26 '14 at 10:39

1 Answers1

0

Jpeg must be enabled when you install GD2; http://php.net/manual/en/image.installation.php

Michael Benjamin
  • 2,895
  • 1
  • 16
  • 18