CodeIgniter Forums
image_create_gd - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: image_create_gd (/showthread.php?tid=67040)

Pages: 1 2


image_create_gd - Knutsford - 01-06-2017

png's are not working in image_create_gd


I have put

error_reporting(E_ALL);
ini_set('display_errors', 1); 



Bu there are no error messages, log messages or anything to what what the problem is






Code:
function image_create_gd($path = '', $image_type = '')
    {
        echo "xxxx - aa";
        if ($path == '')
            $path = $this->full_src_path;

        if ($image_type == '')
            $image_type = $this->image_type;
echo $path;
echo "xxxx - bb";
echo $image_type;
        switch ($image_type)
        {
            case     1 :
                        if ( ! function_exists('imagecreatefromgif'))
                        {
                            $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
                            return FALSE;
                        }

                        return imagecreatefromgif($path);
                break;
            case 2 :
                        if ( ! function_exists('imagecreatefromjpeg'))
                        {
                            $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
                            return FALSE;
                        }

                        return imagecreatefromjpeg($path);
                break;
            case 3 :
                        echo "xxxx - cc";
                        if ( ! function_exists('imagecreatefrompng'))
                        {
                            echo "xxxx - dd";
                            $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
                            return FALSE;
                        }
echo "xxxx - eee";
echo $path;


$a = getimagesize($path);
echo "width = " . $a[0];
echo "height = " . $a[1];
echo "type = " . $a[2];
echo "<img src='" . $path .  "'/>";

$test = imagecreatefrompng($path);
if (false === $test)
{
   echo "xxxx - ffff";
}

echo "xxxx - ggg";
                        return imagecreatefrompng($path);
                break;

        }

        $this->set_error(array('imglib_unsupported_imagecreate'));
        return FALSE;
    }




echo "xxxx - aa"; is coming out

echo "xxxx - cc"; is coming out

then
echo "xxxx - eee"; is coming out

so imagecreatefrompng exists

echo $path; gives



home/sweetlocation/public_html/assets/properties/216841/md/1.png


$a = getimagesize($path);
echo "width = " . $a[0];
echo "height = " . $a[1];
echo "type = " . $a[2];

gives

width = 620height = 413type = 3


Then nothing at all. No echo messages, log messages or error messages. It just stops 100% dead on imagecreatefrompng($path). I have no idea why or what to do

















RE: image_create_gd - Narf - 01-06-2017

What happens if you manually call imagecreatefrompng($theImagePath) ? Not inside CI, just in a one-line PHP script or via php -a under CLI.


RE: image_create_gd - Knutsford - 01-06-2017

That works



I have uploaded a test page


<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$path = "/home/sweetlocation/public_html/assets/properties/216841/md/1.png";
echo $path;


$a = getimagesize($path);
echo "width = " . $a[0];
echo "height = " . $a[1];
echo "type = " . $a[2];


$test = imagecreatefrompng($path);

echo $test;

echo "hhhh";
?>



and I get


/home/sweetlocation/public_html/assets/properties/216841/md/1.pngwidth = 620height = 413type = 3Resource id #3hhhh







Does that give a clue as to what the problem is?


RE: image_create_gd - Narf - 01-06-2017

No, and the only difference I see is that there's no leading slash for $path in your first post - that is very important, so it may be the cause if it's a typo.


RE: image_create_gd - Knutsford - 01-06-2017

There is a / - sorry it got missed when pasting


I have no idea what to do then


RE: image_create_gd - Narf - 01-06-2017

Well, then the issue is probably not inside image_create_gd() ...


RE: image_create_gd - Knutsford - 01-06-2017

I has to be




Case 3 is now 100% the same as my test page





Test page






<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$path = "/home/sweetlocation/public_html/assets/properties/216841/md/1.png";
echo $path;


$a = getimagesize($path);
echo "width = " . $a[0];
echo "height = " . $a[1];
echo "type = " . $a[2];


$test = imagecreatefrompng($path);

echo $test;

echo "hhhh";
?>







Cae 3



case 3 :
$path = "/home/sweetlocation/public_html/assets/properties/216841/md/1.png";
echo $path;


$a = getimagesize($path);
echo "width = " . $a[0];
echo "height = " . $a[1];
echo "type = " . $a[2];


$test = imagecreatefrompng($path);

echo $test;

echo "hhhh";
return "bbb";







Test page I get



/home/sweetlocation/public_html/assets/properties/216841/md/1.pngwidth = 620height = 413type = 3Resource id #3hhhh




switch 3 I only get



/home/sweetlocation/public_html/assets/properties/216841/md/1.pngwidth = 620height = 413type = 3


RE: image_create_gd - Narf - 01-06-2017

I don't understand how that shows anything or that it "has to be". You're not even showing how you're triggering image_create_gd() ...

Also, please use the code formatting provided by the forum; it's very hard to read your posts.


RE: image_create_gd - Knutsford - 01-06-2017

(01-06-2017, 09:25 AM)Narf Wrote: I don't understand how that shows anything or that it "has to be". You're not even showing how you're triggering image_create_gd() ...

Also, please use the code formatting provided by the forum; it's very hard to read your posts.

Sorry - the quick reply doesn't have formatting which was why. This is the code that should do the resize






Code:
if ($index >= $limit) { CONTINUE; }
            
            $image = str_replace(' ', '%20', $image);
            $image = str_replace('#', '%23', $image);
            if (strtolower(substr($image, -3)) == "png") {            
               $target = $this_dir . '/' . ++$index . '.png';
            }
            else {
                $target = $this_dir . '/' . ++$index . '.jpg';
            }
                
            if ($size == 'md') {
            
                // copy here
                copy($image, $target);
                // resize to 'md' size
                $resize_config['source_image'] = $target;
                $resize_config['new_image'] = $target;
                $resize_config['width'] = $dimensions['width'];
                $resize_config['height'] = $dimensions['height'];
                $resize_config['master_dim'] = 'width';
                
                $ci->image_lib->initialize($resize_config);
                
                if (!$ci->image_lib->resize()){
                
                   
                    $log_data = array(
                       'agent_id' => 0,
                       'status' => $ci->image_lib->display_errors(),
                       'error' => 1
                   );
               }
                       echo "kkk";



RE: image_create_gd - Knutsford - 01-06-2017

(01-06-2017, 09:45 AM)Knutsford Wrote:
(01-06-2017, 09:25 AM)Narf Wrote: I don't understand how that shows anything or that it "has to be". You're not even showing how you're triggering image_create_gd() ...

Also, please use the code formatting provided by the forum; it's very hard to read your posts.

Sorry - the quick reply doesn't have formatting which was why. This is the code that should do the resize






Code:
if ($index >= $limit) { CONTINUE; }
            
            $image = str_replace(' ', '%20', $image);
            $image = str_replace('#', '%23', $image);
            if (strtolower(substr($image, -3)) == "png") {            
               $target = $this_dir . '/' . ++$index . '.png';
            }
            else {
                $target = $this_dir . '/' . ++$index . '.jpg';
            }
                
            if ($size == 'md') {
            
                // copy here
                copy($image, $target);
                // resize to 'md' size
                $resize_config['source_image'] = $target;
                $resize_config['new_image'] = $target;
                $resize_config['width'] = $dimensions['width'];
                $resize_config['height'] = $dimensions['height'];
                $resize_config['master_dim'] = 'width';
                
                $ci->image_lib->initialize($resize_config);
                
                if (!$ci->image_lib->resize()){
                
                   
                    $log_data = array(
                       'agent_id' => 0,
                       'status' => $ci->image_lib->display_errors(),
                       'error' => 1
                   );
               }
                       echo "kkk";




It is copying the image but not resizing it or carrying on and doing the next image in the array or creating the sm library or putting anything in the sm library