在我使用 ckEditor 作为 BBCode 编辑器的任务中,我的网站直接遇到了问题。
我有用户提交的内容,可以包含 [img] 标签。
我真的希望图像的宽度为 100%,这很好。我将任何 [img] 标签转换为 html 并应用一个按照我的意愿设计样式的类。
function basicbbcode($text) {
$text = str_replace("[IMG]", "<img class='buildimage' src='", "$text");
$text = str_replace("[/IMG]", "'>", "$text");
$text = str_replace("[img]", "<img class='buildimage' src='", "$text");
$text = str_replace("[/img]", "'>", "$text");
}
问题是当有人使用小/低分辨率图像时。我不想拉伸(stretch)这个图像,因为它看起来很可怕。
我的目标是找到一个阈值,因此如果图像宽度超过 800px,则将其指定为 buildimage 类。如果它较小,则给它一个 buildimage-small 类。
然后我会保持该图像的自然大小。我正在努力促进用户提供高质量的图像,但同时希望保持网站看起来很棒,并且不会因为分辨率很小而出现拉伸(stretch)不良的图像。
那么,有没有办法在图像大小作为 $text 变量从数据库中检查出来时检查图像大小,然后采取相应的操作。最好使用 php,但也可以使用 jquery?
对此一无所知,可能吗?
最佳答案
您可以使用getimagesize()
:
The getimagesize() function will determine the size of any given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondant HTTP content type.
<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
?>
关于php - 转换 BBCode 文本时检查图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20893850/