php裁剪图像而不上传它
//Your Image
$imgSrc = "image.jpg";
list($width, $height) = getimagesize($imgSrc);
$myImage = imagecreatefromjpeg($imgSrc);
if ($width > $height) {
$y = 0;
$x = ($width - $height) / 2;
$smallestSide = $height;
} else {
$x = 0;
$y = ($height - $width) / 2;
$smallestSide = $width;
}
$thumbSize = 100;
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
//Output
imagejpeg($thumb);
页面审查:
<?php
$sql1 = mysql_query("SELECT * FROM images");
while($row_img = mysql_fetch_array($sql1)){
$img_url=$row_img['3']; ?>
<img src="/<? echo $img_url; ?>" />
<?php } ?>
我想使用此代码来查看数据库中的照片。
我在数据库 $imgSrc=$img_url;
中的图像名称是行名称。
谢谢
//Your Image
$imgSrc = "image.jpg";
list($width, $height) = getimagesize($imgSrc);
$myImage = imagecreatefromjpeg($imgSrc);
if ($width > $height) {
$y = 0;
$x = ($width - $height) / 2;
$smallestSide = $height;
} else {
$x = 0;
$y = ($height - $width) / 2;
$smallestSide = $width;
}
$thumbSize = 100;
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
//Output
imagejpeg($thumb);
PAGE REVIEW :
<?php
$sql1 = mysql_query("SELECT * FROM images");
while($row_img = mysql_fetch_array($sql1)){
$img_url=$row_img['3']; ?>
<img src="/<? echo $img_url; ?>" />
<?php } ?>
I want to use this code with while to view my photo from database.
my image name in db $imgSrc=$img_url;
that is row name.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这会起作用
This will work
创建一个名为 resizer.php 的文件,并将以下代码写入该文件(resizer.php)
resizer.php 文件用法
检查一下...
create a file names resizer.php and write down the codes below to that file(resizer.php)
resizer.php file usage
check it out...