{"action":"opened","issue":{"url":"https://api.github.com/repos/octobercms/october/issues/2144","repository_url":"https://api.github.com/repos/octobercms/october","labels_url":"https://api.github.com/repos/octobercms/october/issues/2144/labels{/name}","comments_url":"https://api.github.com/repos/octobercms/october/issues/2144/comments","events_url":"https://api.github.com/repos/octobercms/october/issues/2144/events","html_url":"https://github.com/octobercms/october/issues/2144","id":161804558,"number":2144,"title":"Add BMP image support in the library/src/Database/Attach/Resizer.php class","user":{"login":"robinbonnes","id":5117166,"avatar_url":"https://avatars.githubusercontent.com/u/5117166?v=3","gravatar_id":"","url":"https://api.github.com/users/robinbonnes","html_url":"https://github.com/robinbonnes","followers_url":"https://api.github.com/users/robinbonnes/followers","following_url":"https://api.github.com/users/robinbonnes/following{/other_user}","gists_url":"https://api.github.com/users/robinbonnes/gists{/gist_id}","starred_url":"https://api.github.com/users/robinbonnes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robinbonnes/subscriptions","organizations_url":"https://api.github.com/users/robinbonnes/orgs","repos_url":"https://api.github.com/users/robinbonnes/repos","events_url":"https://api.github.com/users/robinbonnes/events{/privacy}","received_events_url":"https://api.github.com/users/robinbonnes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-06-22T22:50:27Z","updated_at":"2016-06-22T22:50:27Z","closed_at":null,"body":"Hello,\r\n\r\nWhen I upload images straight from my camera's sdcard using the RJGallery plugin, it gives the following error:\r\n\r\nimagesx() expects parameter 1 to be resource, boolean given\r\nvendor/october/rain/src/Database/Attach/Resizer.php line 80\r\n\r\nThis happens because the uploaded (jpg) image has the mime type: image/x-ms-bmp\r\n\r\nIn the 'openImage' function there is no support for that mime type, and createfromjpg is not working because its an bmp image.\r\n\r\nWhat I did to fix this for me:\r\n\r\nAdd to line 244 of Resizer.php:\r\n\r\ncase 'image/x-ms-bmp': $img = $this->imagecreatefrombmp($filePath); break;\r\n\r\nAdd below the openImage function (line 251):\r\n\r\n   /**\r\n     * Create an image from bmp\r\n     * @param string $fileName\r\n     * @return resource\r\n     */\r\n    function imagecreatefrombmp($fileName) {\r\n        $file = fopen($fileName, \"rb\");\r\n        $read = fread($file, 10);\r\n        while (!feof($file) && ($read <> \"\"))\r\n            $read .= fread($file, 1024);\r\n        $temp = unpack(\"H*\", $read);\r\n        $hex = $temp[1];\r\n        $header = substr($hex, 0, 108);\r\n        if (substr($header, 0, 4) == \"424d\") {\r\n            $parts = str_split($header, 2);\r\n            $width = hexdec($parts[19] . $parts[18]);\r\n            $height = hexdec($parts[23] . $parts[22]);\r\n            unset($parts);\r\n        }\r\n        $x = 0;\r\n        $y = 1;\r\n        $image = imagecreatetruecolor($width, $height);\r\n        $body = substr($hex, 108);\r\n        $body_size = (strlen($body) / 2);\r\n        $header_size = ($width * $height);\r\n        $usePadding = ($body_size > ($header_size * 3) + 4);\r\n        for ($i = 0; $i < $body_size; $i+=3) {\r\n            if ($x >= $width) {\r\n                if ($usePadding)\r\n                    $i += $width % 4;\r\n                $x = 0;\r\n                $y++;\r\n                if ($y > $height)\r\n                    break;\r\n            }\r\n            $i_pos = $i * 2;\r\n            $r = hexdec($body[$i_pos + 4] . $body[$i_pos + 5]);\r\n            $g = hexdec($body[$i_pos + 2] . $body[$i_pos + 3]);\r\n            $b = hexdec($body[$i_pos] . $body[$i_pos + 1]);\r\n            $color = imagecolorallocate($image, $r, $g, $b);\r\n            imagesetpixel($image, $x, $height - $y, $color);\r\n            $x++;\r\n        }\r\n        fclose($file);\r\n        unset($body);\r\n        return $image;\r\n    }\r\n\r\nOfcourse this is not a proper fix because it will be gone when I update the core. However what do you guys think, should there be support for this mime type, or should I convert all images first before uploading?\r\n\r\n- Robin\r\n\r\n"}}
{"actor":{"display_login":"robinbonnes"}}