2016-03-22 16 views
0

Minik resimler oluşturan bu kodları web sitesinde başka bir yere koymadan yazdırayım. Bunu yaptığımda ve çıktıyı gösterdiğinde, bu iyi çalışıyor.Küçük resimleri küçük resimleri oluşturmadan kaydedin

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); 

Bu kod i bu imageThumbnail php dosyasına bazı veri göndermek ve daha sonra veritabanına bir sorgu yapmak ve doğru bulmaktı istediğini Şimdi burada creating thumbnails without saving them

alındı Alınan belirli bir veri için yol, ancak çıkış, beklendiği gibi değildi ve görüntü görünmüyordu.

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); 

Ne sorundur ve nasıl ben bunu başarmak yok

Html code

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

+0

biz gerçekten sorunuzu yanıtlamak için bu kodu tüm ihtiyacınız var mı? – m02ph3u5

+0

Evet, bence tüm bunlar önemli ve benim sorum ile ilgili. @ m02ph3u5 – Mitali

+0

@ m02ph3u5 sorumuzu daha az kodla güncelledi – Mitali

cevap

0

Bu kodda dosya gerektirir ve bunun yerine tüm kodu kullanın.

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); 
} 



?> 

bu kodu kullanın .Bu çalışıyor.

1

ne dersiniz:

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); 
İlgili konular