2014-09-04 22 views
0

我正在嘗試調整圖像大小並將其顯示在瀏覽器中。我使用php_image_magician從數據庫調整圖像大小。它成功地調整了圖像的大小。我想顯示圖像而不是saveImage($magicianObj -> saveImage('img.jpeg');)。我怎麼迴應這個圖像正常echo "<img src='".???."' />";php魔術師調整大小 - 顯示圖像而不是保存到文件夾

require_once(PAGEINC.'php_image_magician.php'); 
$magicianObj = new imageLib("http://localhost".$newsfirstimgpath); 
$magicianObj -> resizeImage(50, 50, 'crop'); 
$magicianObj -> saveImage('img.jpeg'); 
+0

你的意思 標題(「內容類型:圖像/ JPEG」); echo(file_get_contents(「img.jpeg」)); – Sunand 2014-09-04 05:06:56

+0

我想顯示圖像而不是saveimage。我不想將調整大小的圖像保存到文件夾 – Karuppiah 2014-09-04 05:09:43

+0

你試過$ im = $ magicianObj - > resizeImage(50,50,'crop')然後標題('Content-Type:image/jpeg'); //輸出圖像 imagejpeg($ im); – light94 2014-09-04 05:16:07

回答

0

您可以使用圖書館的displayImage功能如下:

$magicianObj->displayImage('jpeg',100); // first param tells display as jpeg and second specifies the quality of the image 

你可以找到在this link檢查線路沒有2529其他可用的功能爲displayImage參考

編輯

添加下面的函數略高於displayImage功能在php_image_magician.php

public function getImageSrc($fileType = 'jpg') { 
    ob_start(); 
    if (!is_resource($this->imageResized)) { if ($this->debug) { die('saveImage: This is not a resource.'); }else{ die(); }} 

    switch($fileType) 
    { 
     case 'jpg': 
     case 'jpeg': 
      imagejpeg($this->imageResized, NULL, $imageQuality); 
      break; 
     case 'gif': 
      imagegif($this->imageResized); 
      break; 
     case 'png': 
      // *** Scale quality from 0-100 to 0-9 
      $scaleQuality = round(($imageQuality/100) * 9); 

      // *** Invert qualit setting as 0 is best, not 9 
      $invertScaleQuality = 9 - $scaleQuality; 

      imagepng($this->imageResized, NULL, $invertScaleQuality); 
      break; 
     case 'bmp': 
      die('bmp file format is not supported.'); 
      break; 
     default: 
      // *** No extension - No save. 
      die('file extension not supported.'); 
      break; 
    } 
    $response = ob_get_contents(); 
    ob_end_clean(); 
    return 'data:image/'.$fileType.';base64,' . base64_encode($response); 
} 

而且使用下面的代碼回波圖像:

echo '<img src="'.$magicianObj->getImageSrc('jpeg').'" />'; 
+0

imagejpeg():文件名不能爲空2519行錯誤 – Karuppiah 2014-09-04 05:25:51

+0

看起來像庫中有bug,你可以做一件事,把'imagejpeg($ this-> imageResized,'',$ imageQuality);'改成'imagejpeg $ this-> imageResized,NULL,$ imageQuality);'在'displayImage'函數中,並且爲'imagepng'等其他類似的函數執行此操作。 – 2014-09-04 05:37:04

相關問題