Imagecreatefrom和getimagesize功能不起作用

时间:2017-03-25 09:56:20

标签: php

我使用Imagecreatefrom函数和getimagesize函数在我的代码中使用所有这些函数(Imagecreatefrompng,Imagecreatefromgif,Imagecreatefromjpg)但函数不起作用,它们总是返回false值。我检查了我的服务器上的GD库,它启用了这里的附件,用于GD库描述(https://nimbus.everhelper.me/client/notes/share/830535/amshm8dtowo3t75vrq9g)和我的服务器的PHP版本是(5.4.45)我使用了以下代码:

add_action('wp_ajax_UploadSkins','UploadSkins');

function UploadSkins()
{
    extract($_REQUEST);
    $upload_dir = wp_upload_dir();
    $ThumbSquareSize        = 100; //Thumbnail will be 57X57
    $Quality                = 90; //jpeg quality
    $DestinationDirectory   = $upload_dir['path'].'/'; //specify upload directory ends with / (slash)
    $AcceessUrl             = $upload_dir['url'].'/';
    $ThumbPrefix            = "cmicon_";

    $data = $_REQUEST["custom_imgurl"];
    $params = array();
    parse_str($data, $params);

    foreach($params as $key => $value)
    {
        $custom_imgurl = $value;
        if(!empty($custom_imgurl))
        {
            $sfsi_custom_files[] = $custom_imgurl;
            list($CurWidth, $CurHeight) = getimagesize($custom_imgurl);

            $info = explode("/", $custom_imgurl);
            $iconName = array_pop($info);
            $ImageExt = substr($iconName, strrpos($iconName, '.'));
            $ImageExt = str_replace('.','',$ImageExt);

            $iconName = str_replace(' ','-',strtolower($iconName)); // get image name
            $ImageType = 'image/'.$ImageExt;

             switch(strtolower($ImageType))
             {
                    case 'image/png':
                            // Create a new image from file 
                            $CreatedImage =  imagecreatefrompng($custom_imgurl);
                            break;
                    case 'image/gif':
                            $CreatedImage =  imagecreatefromgif($custom_imgurl);
                            break;
                    case 'image/jpg':
                            $CreatedImage = imagecreatefromjpeg($custom_imgurl);
                            break;                  
                    case 'image/jpeg':
                    case 'image/pjpeg':
                            $CreatedImage = imagecreatefromjpeg($custom_imgurl);
                            break;
                    default:
                             die(json_encode(array('res'=>'type_error'))); //output error and exit
            }

            $ImageName = preg_replace("/\\.[^.\\s]{3,4}$/", "", $iconName);
            $NewIconName = "icon".$key.'.'.$ImageExt;
            $iconPath   = $DestinationDirectory.$NewIconName; //Thumbnail name with destination directory

            return $iconPath;

        }   
    }
}

0 个答案:

没有答案