ImageMagick not supported with wp_get_image_editor on some servers

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
deemi
Posts: 1
Joined: 2015-10-27T05:42:48-07:00
Authentication code: 1151
Location: Lahore, Pakistan
Contact:

ImageMagick not supported with wp_get_image_editor on some servers

Post by deemi »

Hi there, this is my first question on this board so if there any spell, grammar or board rules mistakes please ignore it.

I am php MySQL developer and WordPress theme / plugin developer also. So i create a plugin for products catalogue and upload images more than one. In my older versions i give option in plugin settings page that user can set dimensions for big and thumb images and on front i just re-size images width and height in css with giving dimensions but all images get stretched. Many users complain about this issue.

I searched re-sizing images and found out this function of WordPress

Code: Select all

wp_get_image_editor
and also get very useful link for cropping or re size images http://bhoover.com/wp_image_editor-word ... -tutorial/. I read this tutorial very carefully and found that ImageMagick lib must be enable on the server of the user. I write the script in my plugin for crop images by giving dimensions in settings page.

Here is code sample:

Code: Select all

$upload_dir = wp_upload_dir();
$_image_width = get_option('_image_width');
$_image_height = get_option('_image_height');
$_thumb_width = get_option('_thumb_width');
$_thumb_height = get_option('_thumb_height');

$_product_images = get_post_meta($post->ID, 'product_images', true);

$big_img_name = array();
$thumb_img_name = array();
foreach ($_product_images as $_prod_img) {
              /// For Big
              $big_resize_img = wp_get_image_editor($_prod_img['product_img']);
               if (!is_wp_error($big_resize_img)) {
               $product_big_img = $_prod_img['product_img'];

               $product_img_explode = explode('/', $product_big_img);
               $product_img_name = end($product_img_explode);
               $product_img_name_explode = explode('.', $product_img_name);

               $product_img_name = $product_img_name_explode[0];
               $product_img_ext = $product_img_name_explode[1];

               $big_crop = array('center', 'center');
               $big_resize_img->resize($_image_width, $_image_height, $big_crop);
               $big_filename = $big_resize_img->generate_filename('big-' . $_image_width . 'x' . $_image_height, $upload_dir['path'], NULL);
               $big_resize_img->save($big_filename);

               $big_img_name[]['_big_img'] = $upload_dir['url'] . '/' . $product_img_name . '-big-' . $_image_width . 'x' . $_image_height . '.' . $product_img_ext;
}
update_post_meta($post->ID, '_big_images', $big_img_name);

The images cropped very successfully and save images path in the DB. So i launch the plugin's new version and and it worked very perfectly for users except one !!!! :?. The images not re-sized when he upgrade from older to newer version.

I checked and debug the code on this site. When i print this variable "$big_resize_img" its print me this message

Code: Select all

WP_Error Object
(
    [errors] => Array
        (
            [invalid_image] => Array
                (
                    [0] => El archivo no es una imagen.
                )

        )

    [error_data] => Array
        (
            [invalid_image] => http://www.siteurl.com/wp-content/uploads/Wallpaper_1.jpg
        )

)
But when i print out this variable "$big_resize_img" where images are cropped it gives me no error.

I asked to user that, is ImageMagick is enable on his server he told me yes, so i asked him to create a php file and write "php_info()" and execute this file. The output not show us ImageMagick lib just GD lib is enabled, so again i asked the user for this he create another php file and write code to show ImageMagick version etc.

Code is:

Code: Select all

<?
//This function prints a text array as an html list.
function alist ($array) {  
  $alist = "<ul>";
  for ($i = 0; $i < sizeof($array); $i++) {
    $alist .= "<li>$array[$i]";
  }
  $alist .= "</ul>";
  return $alist;
}
//Try to get ImageMagick "convert" program version number.
exec("convert -version", $out, $rcode);
//Print the return code: 0 if OK, nonzero if error. 
echo "Version return code is $rcode <br>"; 
//Print the output of "convert -version"    
echo alist($out); 
?>
And output is:

Code: Select all

Version return code is 0

    Version: ImageMagick 6.7.2-7 2015-07-23 Q16 http://www.imagemagick.org
    Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
    Features: OpenMP
Q: Is that means ImageMagick lib is enabled?

So, Please tell me what is the issue because i launched newer version 4 months before and only this user get this issue. His site url is http://www.tentebien.com/

One More thing, is this possible if i disable the imagemagick lib but wp_get_image_editor still working because i search and almost every site tells me that the ImageMagick or GD lib is compulsory for 'wp_get_image_editor', so i don't get the point because i disable ImageMagick lib on my server but its still working.

Please tell me what is the issue because this issue has been occurring for three weeks now
Post Reply