• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] CI 3.1.0 ImageMagick not working

#1
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'... );
download and make your system directory strict
Reply

#2
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);

download and make your system directory strict
Reply

#3
!!!! 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!
Reply

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

https://github.com/bcit-ci/CodeIgniter/issues/4736
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply

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

#6
(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.
Reply

#7
(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.
Reply

#8
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.
Reply

#9
(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?
download and make your system directory strict
Reply

#10
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);    

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.