2017-08-01 124 views
0

我有兩個獨立的類中的兩個函數,都有一些Imagick處理。 我想讓第一個Imagick調整圖像大小,然後將其發送到另一個Imagick實例,而不將其另存爲一個文件。Imagick輸出到Imagick的另一個功能(不保存)

在第一類作物

  function cropimage($inputfile){ 
      $image = new Imagick($inputfile); 
      $image->cropimage($w, $h, $x, $y); 
      # and here I wish to return some $image->output???() which let me to use it in second class 
     return ????; 
     } 

而在第二類調整

 function resizeImage(){ 
     $crop = new crop(); // my first class instance 
     $image_to_work = $crop->cropimage($this->image); // output from first class 
     $image = new Imagick($image_to_work); 

     $image->resizeImage($width, $height); 
     $image->writeImage($outputfile); 
    } 

任何想法? 在此先感謝。 乾杯

回答

-2

使用會話。

首先,確保您在每個使用會話的腳本中都有session_start()

然後執行諸如$_SESSION['image'] = $image之類的操作,然後您的下一個腳本就可以訪問該會話變量。

0

圖像可以通過各地的變量:

function cropimage($inputfile) { 
    $image = new Imagick($inputfile); 
    $image->cropimage($w, $h, $x, $y); 

    return $image; 
} 

function resizeImageAndSave($image) { 
     $image->resizeImage($width, $height); 
     $image->writeImage($outputfile); 
} 

$image = cropimage("./test.png"); // return the image 
resizeImageAndSave($image); // pass it into the next function 
+0

請更新您的問題,而不是使用意見,因爲代碼是不是在他們的可讀性。 – Danack