2016-03-22 9 views
0

サムネイルを作成してどこかに保存せずにウェブサイトにプリントするこのコードはあります。サムネイルを保存せずに作成

<img src ="imageThumbnail.php" alt="some description"/> 

これは私がこれを行ったときにうまく動作し、出力が表示されました。

imageThumbnail.php

header("Content-type: image/png"); 

$im  = imagecreatefrompng("image.png"); 
list($width, $height) = getimagesize($im); 
$newimage = imagecreatetruecolor($new_width, $new_height); 
imagecopyresampled($newimage, $im, 0, 0, 0, 0, "100", "100", $width, $height); 

imagepng($newimage); 
imagedestroy($newimage); 
imagedestroy($im); 

このコードは、今私が望んでここにcreating thumbnails without saving them

から撮影されたこのimageThumbnailのphpファイルにいくつかのデータを送信し、データベースにクエリを作成し、正しいを取得するということでしたgetとして渡された特定のデータのパス。出力は期待通りではなく、イメージは表示されません。

Html code

<img src ="imageThumbnail.php?product_code=PD1001" alt="some description"/> 

imageThumbnail.phpThis is the modified code

header("Content-type: image/jpeg"); 
$productCode=$_GET['product_code']; 
require 'connect.inc.php'; 
$statement=$mysqli->prepare("select `product_img_name` from `products` where `product_code`=?"); 
$statement->bind_param("s",$productCode); 
$statement->execute(); 
$result=$statement->get_result(); 
while($row=$result->fetch_object()) 
    $pathName=$row->product_img_name; 

$im=imagecreatefromjpeg("cart/images/".$pathName); 
$width=imagesx($im); 
$height=imagesy($im); 
$newimage=imagecreatetruecolor(116,116); 
imagecopyresampled($newimage, $im, 0, 0, 0, 0,'116', '116', $width, $height); 
imagejpeg($newimage); 
imagedestroy($newimage); 
imagedestroy($im); 

問題とどのように私はこれを達成んとは何ですか?

+0

私たちは本当にあなたの質問に答えるためにそのコードのすべてを必要ですか? – m02ph3u5

+0

ええ、これはすべて重要で、私の質問に関連していると思います。 @ m02ph3u5 – Mitali

+0

@ m02ph3u5非常に少ないコードで私の質問を更新しました – Mitali

答えて

0

コード内の必要なファイルを削除し、代わりにコード全体を使用します。正常に動作します.Thisこのコードを使用し

Something like this

<?php 
error_reporting(-1); 
header("Content-type: image/jpeg"); 
$productCode=$_GET['product_code']; 
$db_username = "root"; 
$db_password = ""; 
$host_name = "localhost"; 
$db_name = 'cakenbake'; 
$mysqli = new mysqli($host_name, $db_username, $db_password, $db_name); 
if ($mysqli->connect_error) { 
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error); 
} 

$statement=$mysqli->prepare("select `product_img_name` from `products` where `product_code`=?"); 
$statement->bind_param("s",$productCode); 
if($statement->execute()) 
{ 
    $result=$statement->get_result(); 
    while($row=$result->fetch_object()) 
     $pathName=$row->product_img_name; 
    $im=imagecreatefromjpeg("cart/images/".$pathName); 
    $width=imagesx($im); 
    $height=imagesy($im); 
    $newimage=imagecreatetruecolor(116,116); 
    imagecopyresampled($newimage, $im, 0, 0, 0, 0,'116', '116', $width, $height); 
    imagejpeg($newimage); 
    imagedestroy($newimage); 
    imagedestroy($im); 
} 



?> 

1

はいかが:

require 'connect.inc.php'; 

header("Content-type: image/jpeg"); 
$productCode=$_GET['product_code']; 

$statement=$mysqli->prepare("select `product_img_name` from `products` where `product_code`=?"); 
$statement->bind_param("s",$productCode); 
$statement->execute(); 
$result=$statement->get_result(); 
while($row=$result->fetch_object()) 
    $pathName=$row->product_img_name; 

$im=imagecreatefromjpeg("cart/images/".$pathName); 
$width=imagesx($im); 
$height=imagesy($im); 
$newimage=imagecreatetruecolor(116,116); 
imagecopyresampled($newimage, $im, 0, 0, 0, 0,'116', '116', $width, $height); 
imagejpeg($newimage); 
imagedestroy($newimage); 
imagedestroy($im); 
関連する問題