CodeIgniter Forums
[SOLVED] CI 3.1.0 ImageMagick not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: [SOLVED] CI 3.1.0 ImageMagick not working (/showthread.php?tid=65813)

Pages: 1 2


[SOLVED] CI 3.1.0 ImageMagick not working - John_Betong - 07-27-2016

Platform: Ubuntu 16.0.4.1
CI Ver:  3.1.0

Can someone please check the following:

file: system/libraries/Image_lib.php

PHP Code:
// __LINE__ 890
// exec() might be disabled
if (function_usable('exec'))
{
  
#@exec($cmd, $output, $retval);
 
 if(0):
    
# ORIGINAL SCRIPT NOT WORKING 
 
   @exec($cmd$output$retval);
 
 else:
 
   # THIS WORKS OK
 
   @exec('/usr/bin/convert ' 
 
         .$this->full_src_path 
          
.' -thumbnail ' .$this->width.'x'.$this->height .' '
 
         .$this->full_dst_path 
          
.' 2>&1'$retval);       
        $retval 
count($retval);
  endif; 
     
}#endif (function_usable('exec')) 

I was also unable to get ImageMagick working in previous versions and had to use PHP exec('convert'... );


RE: CI 3.1.0 ImageMagick not working - John_Betong - 07-27-2016

OK, further experimentation and managed a very quick solution:

file: /CodeIgniter-3.1.0/system/libraries/Image_lib.php

PHP Code:
// line: 891
// exec() might be disabled
if (function_usable('exec'))
{
  
// ADDED THIS LINE TO REMOVE SINGLE QUOTES
  
$cmd str_replace("'"""$cmd); 
  @
exec($cmd$output$retval);




RE: [SOLVED] CI 3.1.0 ImageMagick not working - cartalot - 08-23-2016

!!!! THANK YOU FOR POSTING THIS !!!!

Yes I am confirming this is absolutely true. The Image Library using ImageMagick (on a standard server) does not work without this fix, AND it returns an incorrect error message that the path is not set correctly. After many hours of frustration -- after applying this change -- everything worked perfectly. Betong can haz all the reputation points!


RE: [SOLVED] CI 3.1.0 ImageMagick not working - albertleao - 08-23-2016

Haven't looked deep into this, but is this related to this?

https://github.com/bcit-ci/CodeIgniter/issues/4736


RE: [SOLVED] CI 3.1.0 ImageMagick not working - cartalot - 08-23-2016

The server is Linux Apache running PHP 5.6
i'm using CI_VERSION 3.2.0-dev


RE: [SOLVED] CI 3.1.0 ImageMagick not working - Narf - 08-24-2016

(08-23-2016, 04:00 PM)cartalot Wrote: The server is Linux Apache running PHP 5.6
i'm using CI_VERSION 3.2.0-dev

Seriously, for the Nth time - stop using the develop branch. It is NOT stable, of course you'll have problems with it.


RE: [SOLVED] CI 3.1.0 ImageMagick not working - cartalot - 08-24-2016

(08-24-2016, 02:58 AM)Narf Wrote:
(08-23-2016, 04:00 PM)cartalot Wrote: The server is Linux Apache running PHP 5.6
i'm using CI_VERSION 3.2.0-dev

Seriously, for the Nth time - stop using the develop branch. It is NOT stable, of course you'll have problems with it.

Ok then lets download and try the official 3.1.0 link from the home page and use that system. And it does not work. It gives the error message that the path to the image library is not correct.

Then lets download the 3.1 'stable' branch from Github and use that system. And that version does not even do the upload and it does not return any errors - it just gives a white screen. That situation is why earlier this month I started using 3.2.0 dev because it does not have the upload issue.

So again the only fix i found that did work for getting ImageMagick to work was what was posted above by John Betong. And going into more details for anyone that is interested - the reason that I had to switch over to ImageMagick is that GD2 - which is the default -  does not convert PNG files to JPG. You can do 'new_image' and add the .jpg and it will look like everything is working, but its does not actually convert the file format and the images are huge file sizes.


RE: [SOLVED] CI 3.1.0 ImageMagick not working - Diederik - 08-24-2016

I'm not using the codeigniter image manipulation library myself so I dont know if it can help you with the conversion. But it's so easy in regular php:
PHP Code:
function png2jpg($originalFile$outputFile$quality) {
 
   $image imagecreatefrompng($originalFile);
 
   imagejpeg($image$outputFile$quality);
 
   imagedestroy($image);

I would not want to be dependent of the availability of the exec command in my application since it is usualy turned off on a shared hosting server.


RE: [SOLVED] CI 3.1.0 ImageMagick not working - John_Betong - 08-24-2016

(08-24-2016, 08:17 PM)Diederik Wrote: I'm not using the codeigniter image manipulation library myself so I dont know if it can help you with the conversion. But it's so easy in regular php:
PHP Code:
function png2jpg($originalFile$outputFile$quality) {
 
   $image imagecreatefrompng($originalFile);
 
   imagejpeg($image$outputFile$quality);
 
   imagedestroy($image);

I would not want to be dependent of the availability of the exec command in my application since it is usualy turned off on a shared hosting server.

I am using PHP to create a dynamic SVG chart and then using ImageMagick to convert the chart to PNG. The image can then easily be emailed.

Is there a similar PHP conversion function?


RE: [SOLVED] CI 3.1.0 ImageMagick not working - Diederik - 08-25-2016

GD2 has no support for SVG images, so you indeed need to use ImageMagik. You can try using the function below instead of the exec() approach.

PHP Code:
function svg2png($originalFile$outputFile$width=800$height=600) {
 
   $image = new \Imagick(realpath($originalFile));
 
   $image->setImageFormat("png24");
 
   $image->resizeImage($width$heightimagick::FILTER_LANCZOS1); 
 
   $image->writeImage($outputFile);