php 上传没有背景的PNG图像后,在Laravel中会出现黑色背景,请检查

6qqygrtg  于 2022-11-28  发布在  PHP
关注(0)|答案(1)|浏览(158)
private function processImageUpload($image,$image_name){
        //using image png function to change any image from jpeg to png and store to public folder
        $img  = imagepng(imagecreatefromstring(file_get_contents($image)), config('app.LOGO_MEDIA_PATH').'/'.$image_name.'.png');

        /*
       * TODO : change the image replacing functionality
       * from static name to upload to uploads folder
       * and get URL form settings table
       */

        $url = "/front/common/img/".$image_name.'.png';
        return $url;
    }

我在php.ini文件中启用了imagick扩展,但没有发生任何事情

ru9i0ody

ru9i0ody1#

我得到了解决方案。。只是需要添加的图像类型的情况下。在这方面,我们不能转换为png的png。

private function processImageUpload($image,$image_name){
    if($image->getMimeType() !== "image/png"){
        //using image png function to change any image from jpeg to png and store to public folder
        $img  = imagepng(imagecreatefromstring(file_get_contents($image)), config('app.LOGO_MEDIA_PATH').'/'.$image_name.'.png');
    }else{
        $image->move(config('app.LOGO_MEDIA_PATH'), $image_name.'.png');
    }

    /*
    * TODO : change the image replacing functionality
    * from static name to upload to uploads folder
    * and get URL form settings table
    */
    
    $url = "/front/common/img/".$image_name.'.png';
    return $url;
}

相关问题