2015-09-04 68 views
0

我有一个查询在我的PHP网站。 我想在点击按钮上显示图像。 现在图像在不同的网页中打开,但我需要在同一个网页中打开它,并使用一些类似imageViewer的效果。 代码段赞赏。 感谢如何jquery插件在AJAX调用

<script type="text/javascript"> 
    $(document).ready(function() { 
    $("#selectedAlbumList").change(function() { 
    $("#loading1").after('<div id="loader1"><img src="img/loading.gif" width="20px" height="20px" alt="loading division" /></div>'); 
    $.get('albumimageGet.php?albumid=' + $("#selectedAlbumList").val() + ' ', function (data) { 
     $("#galleryData").html(data); 
     $('#loader1').slideUp(200, function() 
          { 
     alert(data); 
     $(this).remove(); 
     }); 
    }); 
    }); 
}); 
</script> 

//albumimageGet.php

<div class="gallery" data-toggle="lightbox-gallery"> 
    <div class="row"> 
    <?php 
while ($row = mysql_fetch_array($query)) { 
?> 
    <div class="col-sm-4 gallery-image"> 
     <img src="json/uploads/<?php echo $username; ?>/<?php echo $albumname; ?>/<?php echo $row['imagename']; ?>" alt="image" height="200" width="350"> 
     <div class="gallery-image-options text-center"> 
     <div class="btn-group btn-group-sm"> 
      <a href="json/uploads/<?php echo $username; ?>/<?php echo $albumname; ?>/<?php echo $row['imagename']; ?>" class="gallery-link btn btn-sm btn-alt btn-default" title="Image Info">View</a> 
      <a href="deleteImage.php?albumid=<?php echo $albumid; ?>&imagename=<?php echo $row['imagename']; ?>" class="btn btn-sm btn-alt btn-default" data-toggle="tooltip" title="Delete" style="height:30px;"><i class="fa fa-trash-o"></i></a> 
     </div> 
     </div> 
    </div> 
    <?php 
} 
?> 
    </div> 
</div> 
+0

显示你的代码,请 – Zl3n

+0

代码片段赞赏。谢谢 –

回答

0

你可以试试这个功能来放大或调整图像大小......试试吧....希望这将工作

/*creates thumbnail of required dimensions*/ 
function createThumbnailofSize($sourcefilepath,$destdir,$reqwidth,$reqheight,$aspectratio=false) 
{ 
/* 
* $sourcefilepath = absolute source file path of jpeg 
* $destdir = absolute path of destination directory of thumbnail ending with "/" 
*/ 
$thumbWidth = $reqwidth; /*pixels*/ 
$filename = split("[/\\]",$sourcefilepath); 
$filename = $filename[count($filename)-1]; 
$thumbnail_path = $destdir.$filename; 
$image_file = $sourcefilepath; 

$img = imagecreatefromjpeg($image_file); 
$width = imagesx($img); 
$height = imagesy($img); 

// calculate thumbnail size 
$new_width = $thumbWidth; 
if($aspectratio==true) 
{ 
    $new_height = floor($height * ($thumbWidth/$width)); 
} 
else 
{ 
    $new_height = $reqheight; 
} 

// create a new temporary image 
$tmp_img = imagecreatetruecolor($new_width, $new_height); 

// copy and resize old image into new image 
imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 

// save thumbnail into a file 

$returnvalue = imagejpeg($tmp_img,$thumbnail_path); 
imagedestroy($img); 
return $returnvalue; 
}