2016-02-27 39 views
0

我在將svg2jpg轉換爲嵌入式JPG時遇到了一些問題。 以下代碼在另一臺服務器上完美工作。 嵌入式PNG運行良好,只有JPG會造成麻煩。 `Imagick SVG to JPG - 在渲染結果中缺少jpgs

// iterating all image children 
    foreach ($xml->xpath('//image') as $image) { 
     // fetching the xlink:href attribute 
     $xlinkHref = $image->attributes('xlink', TRUE)->href; 

     if ($xlinkHref != "") { 
      $type = pathinfo($xlinkHref, PATHINFO_EXTENSION); 

      $data = file_get_contents($xlinkHref); 
      $xlinkHref = 'data:image/' . $type . ';base64,' . base64_encode($data); 

      // now setting the new attribute value 
      $image->attributes('xlink', TRUE)->href = $xlinkHref; 
     }      
    } 

ImageMagick的版本:6.7.8-9 2014年6月10日Q16 (代碼工作精細的舊ImageMagick的服務器上版本: 6.7.2-7 2013年3月18日Q16)

有什麼想法?

親切的問候

+0

Imagemagick有時會在其他事情發生變化時破裂。我會安裝一個更新的版本,並嘗試一下,因爲它現在已經是版本6.9了。你的版本大約五歲。 – Bonzo

回答

0

問題是由數據引起的:圖像類型 「數據:圖像/ JPG」沒有工作。必須改爲指定爲「data:image/jpeg」。