新添加后缩略图出现问题 - PHP 即时方法
对于那些可能已经阅读过我几分钟前解决的问题的人>。<
动态 php 脚本工作得很好,但是当我将新图像上传到我自己创建的图库时,图像大小被调整为 150 x 150 以满足我的需求......但是,当涉及到新图像时添加后,它是全黑的...
正如您可以看到上传到文件夹的三个黑色图像以及添加到数据库的目录。
其他(非黑色图像)已使用 image.php 调整大小。
是什么原因造成的?
如果我查看源代码,代码就很好...... PHP 中的 while 循环生成如下输出:
<div class="view-wrap" id="photo-10">
<div class="view-icon">
<div class="img-label">
<a href="#" id="10" class="delete"><img src="img/small-delete.png" /> Delete</a>
</div>
<a href="img/events/Paintballing/24251_1395408043148_1170626626_1204038_5382765_n.jpg">
<img src="image.php?dir=img/events/Paintballing/24251_1395408043148_1170626626_1204038_5382765_n.jpg" alt="" width="110" height="110" />
</a>
</div>
</div>
一个块的示例。
如果我查看源代码(在 Firefox 中)并单击 exmaple 的 image.php?dir=img/events/Paintballing/24251_1395408043148_1170626626_1204038_5382765_n.jpg,我可以看到缩略图的大小为 150 x 150,但在布局中,它显示黑色缩略图...
有谁知道为什么会发生这种情况?
编辑:
<?php
$dir = $_GET['dir'];
header('Content-type: image/jpeg');
$create = imagecreatetruecolor(150, 150);
$img = imagecreatefromjpeg($dir);
list($width, $height) = getimagesize($dir);
imagecopyresampled($create, $img, 0, 0, 0, 0, 150, 150, $width, $height);
imagejpeg($create, null, 100);
?>
这是image.php。
to those that may have read my previous question that got solved a couple minutes ago >.<
The on-the-fly php script works perfectly, but when I went to upload new images into a gallery which I made myself, the images are resized to 150 x 150 for what I wanted... however, when it comes to new images being added it is all black...
As you can see the three black images that were uploaded to the folder and the directory added to the database.
The other (non-black images) are already resized with image.php.
What is causing this?
If I view the source, the code is fine... the while loop in the PHP generates an output like this:
<div class="view-wrap" id="photo-10">
<div class="view-icon">
<div class="img-label">
<a href="#" id="10" class="delete"><img src="img/small-delete.png" /> Delete</a>
</div>
<a href="img/events/Paintballing/24251_1395408043148_1170626626_1204038_5382765_n.jpg">
<img src="image.php?dir=img/events/Paintballing/24251_1395408043148_1170626626_1204038_5382765_n.jpg" alt="" width="110" height="110" />
</a>
</div>
</div>
An example of one block.
If I view the source (in Firefox) and click on the image.php?dir=img/events/Paintballing/24251_1395408043148_1170626626_1204038_5382765_n.jpg by exmaple, I can see the thumbnail at it's 150 x 150 size but in the layout, it shows a black thumbnail...
Does anyone know why this is happening?
EDIT:
<?php
$dir = $_GET['dir'];
header('Content-type: image/jpeg');
$create = imagecreatetruecolor(150, 150);
$img = imagecreatefromjpeg($dir);
list($width, $height) = getimagesize($dir);
imagecopyresampled($create, $img, 0, 0, 0, 0, 150, 150, $width, $height);
imagejpeg($create, null, 100);
?>
This is image.php.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢您更新您的帖子。
您确定该图像是您上传的 jpg/jpeg 格式吗?
尝试更改为以下内容
Thanks for updating your post.
Are you positive that the image is a jpg/jpeg that your uploading.
Try changing to the following
为什么不添加边框而不是拉伸图像呢?
这是函数
该函数将替换原始文件,但可以轻松修改以创建新的缩略图。只需更改文件名 imagegif($dst_image, $filename); 行即可
Rather than stretching the images why not add a border?
Here's the function
This function will replace the original file but is easily modified to create a new thumbnail image. Just change the file name the line imagegif($dst_image, $filename);