2

I'm new to PHP. How I can use blob in CodeIgniter? What is the best option for sending an image from the server to a client (RESTful) using codeigniter? I have tried the following:

$newPerson = new Person();
$newPerson->id = 1;
$newPerson->firstName = "Qutfullo";
$newPerson->lastName = "Ochilov";
$image=new Imagick();
$image->setImage("my.jpg");
$newPerson->image=$image->getImageBlob();
$this->response($newPerson);

But I get an exception:

Fatal error: Class 'Imagick' not found.


Thanks for help!

Sotiris Kiritsis
  • 3,178
  • 3
  • 23
  • 31
Qutfullo Ochilov
  • 303
  • 1
  • 10
  • 1
    You would use it the same way as you would without CodeIgniter. Are you working with some code that doesn't work? It would be helpful to see that code, otherwise this question is just far too broad for this site. – MonkeyZeus Mar 31 '16 at 20:59
  • this is error not exception? try to include Class 'Imagick' might be missing in php libraray – Abhishek Apr 01 '16 at 05:09

3 Answers3

1

Hope below snippet can give you the idea that you are missing library --

Try below code if on ubuntu --

php -m | grep imagick.

If the result is empty then issue below commands from terminal

sudo apt-get remove --purge php5-imagick && sudo apt-get install php5-imagick

if on window sserver follow below link instructions that might be useful

Install Imagick for PHP and Apache on Windows

Community
  • 1
  • 1
Abhishek
  • 1,543
  • 3
  • 13
  • 29
1

The error is because of your server have no Image Magic Software suite. First you install it in your server.

For install Image Magic in Unix/Linux

Download ImageMagick.tar.gz from www.imagemagick.org

Unpack the distribution with this command:

tar xvzf ImageMagick.tar.gz

Next configure and compile ImageMagick:

cd ImageMagick-6.9.3
 ./configure
 make

To install, type

sudo make install

You may need to configure the dynamic linker run-time bindings:

sudo ldconfig /usr/local/lib

Install from Windows Source

Download ImageMagick-windows.zip from www.imagemagick.org

Unzip and Install

unzip ImageMagick-windows.zip

Please refer this link for installation.

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
Sinsil Mathew
  • 498
  • 6
  • 20
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/11852481) – Vinoth Krishnan Apr 01 '16 at 05:40
  • 1
    @VinothKrishnan :Agree with you and did editing on my answer – Sinsil Mathew Apr 01 '16 at 05:59
0

If you are developing a RESTFull API, The best way is to send the image URL as the response.

Praneeth Nidarshan
  • 1,704
  • 15
  • 21