Php 从数据库中获取图像的大小

Php 从数据库中获取图像的大小,php,jquery,database,image,lightbox,Php,Jquery,Database,Image,Lightbox,我有一个简单的基于标签的图像库,将所有图像保存在数据库中。要显示这些图像,有一个小的php脚本 <?php include_once("config/config.php"); $mysql_user = USER; $password = PWD; $database_host = HOST; $database = DB; mysql_connect($database_host, $mysql_user, $password) or

我有一个简单的基于标签的图像库,将所有图像保存在数据库中。要显示这些图像,有一个小的php脚本

<?php
    include_once("config/config.php");

    $mysql_user = USER;
    $password = PWD;
    $database_host = HOST;
    $database = DB;

    mysql_connect($database_host, $mysql_user, $password) or die ("Unable to connect to DB server. Error: ".mysql_error());
    mysql_select_db($database);


    header('Content-type: image/jpeg');
    $query = "SELECT imgblob from images where id=". intval($_GET["id"]);
    $rs = mysql_fetch_array(mysql_query($query));
    //echo mysql_error();
    echo base64_decode($rs["imgblob"]);
?>
这些功能并非一直有效。通常,调整图像大小非常小。我不知道该怎么修


这是一个示例库

您需要等待图像加载后才能获得图像大小

var theImage = new Image();
$(theImage).load(function () {
    $(this).fancybox({
        'transitionIn' : 'elastic',
        'transitionOut' : 'elastic',
        'speedIn' : 600,
        'speedOut' : 200,
        'overlayShow' : false,
        'type' : 'iframe',
        'width' : theImage.width + 20,
        'height' : theImage.height + 20
        });
    });
});

theImage.src = img.attr("src");
尽管坦率地说,我完全不明白你为什么要使用不同的
图像。请尝试以下方法:

$('a.lightbox').each(function() {
    var $img = $(this).children("img");

    $(this).fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': false,
        'type': 'iframe',
        'width': $img.width() + 20,
        'height': $img.height() + 20
    });
});​

您需要等待图像加载后才能获得图像大小

var theImage = new Image();
$(theImage).load(function () {
    $(this).fancybox({
        'transitionIn' : 'elastic',
        'transitionOut' : 'elastic',
        'speedIn' : 600,
        'speedOut' : 200,
        'overlayShow' : false,
        'type' : 'iframe',
        'width' : theImage.width + 20,
        'height' : theImage.height + 20
        });
    });
});

theImage.src = img.attr("src");
尽管坦率地说,我完全不明白你为什么要使用不同的
图像。请尝试以下方法:

$('a.lightbox').each(function() {
    var $img = $(this).children("img");

    $(this).fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': false,
        'type': 'iframe',
        'width': $img.width() + 20,
        'height': $img.height() + 20
    });
});​

这里可能会问:使用php获取大小。在使用javascript获取尺寸之前,必须在浏览器中完全加载图像。php可以早在这之前就拥有它们。将维度添加到
数据-
属性中,并从该属性中提取您的维度lightbox@Eritrea如下所述,图像对象提供了中定义的图像的宽度和高度css@charlietfl就这样!非常感谢你。我创建了一个php图像对象,并将宽度和高度保存在输入字段中。Jquery获取值,然后BAM它就可以工作了!!这里可能会问:使用php获取大小。在使用javascript获取尺寸之前,必须在浏览器中完全加载图像。php可以早在这之前就拥有它们。将维度添加到
数据-
属性中,并从该属性中提取您的维度lightbox@Eritrea如下所述,图像对象提供了中定义的图像的宽度和高度css@charlietfl就这样!非常感谢你。我创建了一个php图像对象,并将宽度和高度保存在输入字段中。Jquery获取值,然后BAM它就可以工作了!!您好,我正在使用一个新的图像实例,因为lightbox的图像对象提供了css中定义的小图像大小。所以我使用一个新的对象来生成原始大小的图像。我使用一个新的图像实例,因为lightbox的图像对象给了我css中定义的小图像大小。因此,我使用一个新对象生成原始大小的图像