使用 PHP 建议调整图像大小
根据以前的经验,我注意到到目前为止,我不太擅长将其他人创建的“脚本”与我自己的现有代码集成。我需要一些建议来理解这个人所说的关于使用 PHP 调整图像大小的内容:
在评论中,他写道:
// Parameters need to be passed in through the URL's query string:
// image absolute path of local image starting with "/" (e.g. /images/toast.jpg)
// width maximum width of final image in pixels (e.g. 700)
// height maximum height of final image in pixels (e.g. 700)
然后,他给出了一个实际的例子,也作为评论:
// Resizing and cropping a JPEG into a square:
// <img src="/image.php/image-name.jpg?width=100&height=100&cropratio=1:1&image=/path/to/image.jpg" alt="Don't forget your alt text" />
我猜,他希望脚本的用户类似于上面的img src
。所以,我的问题是:我如何真正使我的图片来源与上面的示例类似?下面是我的一些代码。它显示了我如何保存图片以及如何回显/显示它们。它来自 uploader.php
:
move_uploaded_file($_FILES["file"]["tmp_name"],
"profileportraits/" . $_FILES["file"]["name"]);
echo "Stored in: " . "profileportraits/" . $_FILES["file"]["name"];
将照片保存到文件夹中后,我将文件路径保存在 MySQL 表中,然后调用文件路径来显示图片(下面的代码)。它来自 profile.php
echo "<img src=\"{$row['PortraitPath']}\" />";
因此,如果我使用上面的 img src 来显示“实际”图片,我将如何传递类似于“脚本示例”中的参数?
谢谢。
From previous experiences, I've noticed that I'm not very good at integrating 'scripts' created by others, with my own existing code, as of now. I need some advice on understanding what this person is saying about resizing images with PHP:
In the comments, he's written:
// Parameters need to be passed in through the URL's query string:
// image absolute path of local image starting with "/" (e.g. /images/toast.jpg)
// width maximum width of final image in pixels (e.g. 700)
// height maximum height of final image in pixels (e.g. 700)
Then, he gives an actual example, also as a comment:
// Resizing and cropping a JPEG into a square:
// <img src="/image.php/image-name.jpg?width=100&height=100&cropratio=1:1&image=/path/to/image.jpg" alt="Don't forget your alt text" />
I am guessing, he wants the user of the script to have something similar to the above img src
. So, my question is: How will I actually make the source of my pictures similar to the example above? Below is some of the code I have. It shows how I am saving the pictures and HOW I am echoing/displaying them. It's from uploader.php
:
move_uploaded_file($_FILES["file"]["tmp_name"],
"profileportraits/" . $_FILES["file"]["name"]);
echo "Stored in: " . "profileportraits/" . $_FILES["file"]["name"];
Once the photo has been saved in the folder, I save the file path in a MySQL table and later call the file path to display the picture (Below Code). It's from profile.php
echo "<img src=\"{$row['PortraitPath']}\" />";
Therefore, how will I pass the parameters similar to the one in the 'script example' if I am using the above img src to display the 'actual' picture?
THANK YOU.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下代码来调整图像大小...一旦获得所有参数
希望这有帮助..
谢谢
切坦夏尔马
You can use the following code to resize the image... once you got all the params
Hope this helps..
Thanks
Chetan sharma