我有一個文件叫做$ png_file,它是一個從數據庫中取出的字符串。 我希望能夠以如下方式使用它:如何在PHP函數imagecreatefromstring中使用png字符串?
$image = imagecreatefromstring($png_file);
$width = imagesx($image);
$height = imagesy($image);
,這樣我可以得到保存在數據庫中的字符串PNG文件的高度和寬度。
然而,每次我嘗試這樣做,我得到以下錯誤:
Warning: imagecreatefromstring() [function.imagecreatefromstring]: gd-png: fatal libpng error: Read Error: truncated data in on line 39
Warning: imagecreatefromstring() [function.imagecreatefromstring]: gd-png error: setjmp returns error condition in on line 39
Warning: imagecreatefromstring() [function.imagecreatefromstring]: Passed data is not in 'PNG' format in on line 39
Warning: imagecreatefromstring() [function.imagecreatefromstring]: Couldn't create GD Image Stream out of Data in on line 39
Warning: imagesx() expects parameter 1 to be resource, boolean given in on line 40
Warning: imagesy() expects parameter 1 to be resource, boolean given in on line 41
我怎樣才能解決這個問題?並注意,PNG文件是一個字符串,我不能得到它作爲一個URL
當你不顯示如何獲取圖像數據時,無法幫助您。你沒有顯示任何相關的代碼。無論你的形象是腐敗的,還是你以奇怪的方式獲取它。 – Brad