2012-02-19 2 views
1

thisサムネイルジェネレータを使用しようとしていますが、画像サムを作成するにはthis linkを経由する必要があります。これは疑問な質問かもしれませんが、データベースへの変数を保存するPHPスクリプトの中でどのように動作させるのですか?私は含めようとしましたPHPスクリプト内でサムジェネレータを使用する方法

header("Location: http://www.zubrag.com/thumb.php?src=http://www.test.com/test.jpg&dest=thumb.jpg&x=100&y=50"); 

しかし、動作しません。私は本当に簡単な解決策があると思うが、私はそれを見つけることができない。

答えて

3

は...

スクリプトを呼び出す行で親指を作っている以上のことをしたいですか? thumb.phpからコードの行を出して、あなたのスクリプトでそれを使うだけです。

include('image.class.php'); 

$img = new Zubrag_image; 

// initialize 
$img->max_x  = $max_x; 
$img->max_y  = $max_y; 
$img->cut_x  = $cut_x; 
$img->cut_y  = $cut_y; 
$img->quality  = $image_quality; 
$img->save_to_file = $save_to_file; 
$img->image_type = $image_type; 

// generate thumbnail 
$img->GenerateThumbFile($images_folder . $from_name, $thumbs_folder . $to_name); 

あなたは、希望の値で値を変更するだけでよいのです...これは私のスクリプトを少し見直してもうまくいくはずです。

+0

ありがとう、私はこの解決策について考えていたが、何か他のものがあるかもしれないと思ったが、これはうまくいく。 –

0

あなたは指示を誤解していると思います。これはWebサービスではなく、サーバーにインストールする必要があるPHPスクリプトです。 zubrag.comのURLは単なる例で、あなたのサイトのURLに置き換えます。

+0

を試すことができ、私は自分のサーバーにアップロードこのスクリプトを持って、それが動作しますが、唯一のリンクを介して、私は記述することなく、それを使用したいですブラウザにリンクしてください。 –

+0

これはどのように使用しますか?イメージをユーザーに表示しますか?それをデータベースに保存しますか?変更しますか?電子メールで送信しますか? – JJJ

+0

ファイルからサムネイルを作成したい:)これは、このスクリプトがやっていることです。それは私がやりたいことですが、別のPHPスクリプトの中では、ブラウザにリンクを書くことではありません。 –

0

特定の発電機を持つ任意の個人的な経験がなければ、あなたが画像を表示する必要がありますすることの形で何かになります:私は本当にあなたの問題を見ることができない

<img src="thumb.php?src=link/to/image.jpg&x=100&y=50&f=0"/> 
0

あなたは、私がここでは例として、それを与えたこの

<? 

$property_id = 1; // for our little example here 

define("_IMAGE_PATH","property_images/"); 
// max dimensions allowed: 
define("_IMAGE_WIDTH","640"); 
define("_IMAGE_HEIGHT","480"); 
define("_IMAGE_THUMB_WIDTH","100"); 
define("_IMAGE_THUMB_HEIGHT","75"); 


// grab the path to the temporary file (image) that the user uploaded 
$photo = $_FILES['new_image']['tmp_name']; 
// check if it exists 
if(is_uploaded_file($photo)){ 
    //the real image file name 
    $real_name = strtolower($_FILES['new_image']['name']); 
    // image type based on image file name extension: 
    if(strstr($real_name,".png")){ 
     $image_type = "png"; 
    }else if(strstr($real_name,".jpg")){ 
     $image_type = "jpg"; 
    }else if(strstr($real_name,".gif")){ 
     $image_type = "gif"; 
    }else{ 
     die("Unsupported image type"); 
    } 

    // find the next image name we are going to save 
    $x=1; 
    while(true){ 
     $image_name = _IMAGE_PATH."${property_id}/${x}.jpg"; 
     if(!is_file($image_name))break; 
     $x++; 
    } 

    // start processing the main bigger image: 
    $max_width = _IMAGE_WIDTH; $max_height = _IMAGE_HEIGHT; 
    $size = getimagesize($photo); 
    $width = $size[0]; 
    $height = $size[1]; 
    $x_ratio = $max_width/$width; 
    $y_ratio = $max_height/$height; 
    if(($width <= $max_width)&&($height <= $max_height)){ 
     $tn_width = $width; 
     $tn_height = $height; 
    }else{ 
     if(($x_ratio * $height) < $max_height){ 
      $tn_height = ceil($x_ratio * $height); 
      $tn_width = $max_width; 
     }else{ 
      $tn_width = ceil($y_ratio * $width); 
      $tn_height = $max_height; 
     } 
    } 
    switch($image_type){ 
     case "png": $src=imagecreatefrompng($photo); break; 
     case "jpg": $src=imagecreatefromjpeg($photo); break; 
     case "gif": $src=imagecreatefromgif($photo); break; 
    } 
    // destination resized image: 
    $dst = imagecreatetruecolor($tn_width, $tn_height); 
    // resize original image onto $dst 
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height); 
    // write the final jpeg image.. 
    imagejpeg($dst, $image_name, 100) or die("Error: your photo 
    has not been saved. Please contact the administrator"); 
    // time to clean up 
    imagedestroy($src); 
    imagedestroy($dst); 


    // and now we do it alll again for the thumbnail: 
    $max_width = _IMAGE_THUMB_WIDTH; $max_height = _IMAGE_THUMB_HEIGHT; 
    $size = GetImageSize($photo); 
    $width = $size[0]; 
    $height = $size[1]; 
    $x_ratio = $max_width/$width; 
    $y_ratio = $max_height/$height; 
    if(($width <= $max_width)&&($height <= $max_height)){ 
     $tn_width = $width; 
     $tn_height = $height; 
    }else{ 
     if(($x_ratio * $height) < $max_height){ 
      $tn_height = ceil($x_ratio * $height); 
      $tn_width = $max_width; 
     }else{ 
      $tn_width = ceil($y_ratio * $width); 
      $tn_height = $max_height; 
     } 
    } 
    switch($image_type){ 
     case "png": $src=imagecreatefrompng($photo); break; 
     case "jpg": $src=imagecreatefromjpeg($photo); break; 
     case "gif": $src=imagecreatefromgif($photo); break; 
    } 
    $dst = imagecreatetruecolor($tn_width, $tn_height); 
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height); 
    $thumbfile = $image_name . ".thumb.jpg"; 
    if(file_exists($thumbfile))unlink($thumbfile); 
    imagejpeg($dst, $thumbfile, 100) or die("Error: your photo thumb has not been saved. 
     Please contact the administrator"); 
    imagedestroy($src); 
    imagedestroy($dst); 
} 
?> 
関連する問題