简体   繁体   English

在响应式Web应用程序中使用动态图像

[英]Work with dynamic Images in responsive web application

I am working on responsive web application. 我正在开发响应式Web应用程序。 My designer used 370x700px Images in static pages. 我的设计师在静态页面中使用了370x700px图像。 It works perfectly with responsive with the css and js code for images including this width:100% height:auto . 它可以完美地响应css和js代码的图像,包括这个width:100% height:auto

In this site I am uploading product images from the admin panel.In without responsive website I was creating different size of thumbnails, but In this case I am worried that should I create thumbnail of size 370x700px ? 在这个网站我从管理面板上传产品图片。在没有响应的网站我创建不同大小的缩略图,但在这种情况下,我担心我应该创建大小370x700px缩略图? These images are too big to load and i have to load 10 images on one page. 这些图像太大而无法加载,我必须在一页上加载10张图像。 minimum size of the image is 150kb. 图像的最小尺寸为150kb。 so 150*10 = 1500kb only for images except other contents. 所以150*10 = 1500kb仅适用于除其他内容以外的图像。 These are the small images, big images resolution is around 700x1800px which I will show on product detail page in zoom section. 这些是小图像,大图像分辨率大约700x1800px ,我将在缩放部分的产品详细信息页面上显示。

Is there any other way to do it? 还有其他办法吗? should I create 370*700px thumbnail images from admin panel? 我应该从管理面板创建370 * 700px缩略图?

Here is some old code I wrote that will resize any image from a DB. 以下是我编写的一些旧代码,它将调整DB中的任何图像大小。 It still uses the deprecated mysql_* but that is easy enough for you to update. 它仍然使用已弃用的mysql_ *,但这很容易让您更新。

It is designed to take $GET arguments, img (the row on the db corresponding to the image), min,max,height,width. 它被设计为获取$ GET参数,img(数据库中对应于图像的行),min,max,height,width。 Depending on which of those are set, it will either fix an absolute value or try to fit the image to a size you need. 根据设置的那些,它将固定绝对值或尝试使图像适合您需要的尺寸。 This will allow you to upload one image only then resize that dynamically for your pages. 这样您就可以只上传一张图片,然后动态调整页面大小。

    $sql=sprintf("SELECT image,filetype,width,height FROM image WHERE imageline='%s'",mysql_real_escape_string($_GET['img']));
$result=mysql_query($sql,$dbh);
$row=mysql_fetch_assoc($result);
$filetype=($row['filetype']!="")?$row['filetype']:"image/jpeg";
$content=base64_decode($row['image']);
$newheight=0;
$newwidth=0;
if($row['height']==0||$row['width']==0)
    {

    header("Content-type: $filetype");
    echo ($content);
    die;
    }

if($_GET['max']>0)
    {
    if($row['height']>=$row['width'])
        {
        $_GET['height']=($_GET['max']>$row['height'])?$row['height']:$_GET['max'];
        $_GET['width']=0;
        }
    if($row['width']>$row['height'])
        {
        $_GET['width']=($_GET['max']>$row['width'])?$row['width']:$_GET['max'];
        $_GET['height']=0;
        }
    }

if($_GET['min']>0)
    {
    if($row['height']<=$row['width'])
        {
        $_GET['height']=$_GET['min'];
        $_GET['width']=0;
        }
    if($row['width']<$row['height'])
        {
        $_GET['width']=$_GET['min'];
        $_GET['height']=0;
        }
    }

if($_GET['height']>0&&$_GET['width']==0)
    {
    $newheight=$_GET['height'];
    $newwidth=$row['width']*($_GET['height']/$row['height']);

    }
if($_GET['height']>0&&$_GET['width']>0)
    {
    $newheight=$_GET['height'];
    $newwidth=$_GET['width'];
    }
if($_GET['width']>0&&$_GET['height']==0)
    {
    $newwidth=$_GET['width'];
    $newheight=$row['height']*($_GET['width']/$row['width']);   
    }

if($newheight>0&&$newwidth>0)
    {
    $newheight=floor($newheight);
    $newwidth=floor($newwidth); 
    $image=imagecreatefromstring($content);
    $newimage=imagecreatetruecolor($newwidth, $newheight);
    imagecopyresampled($newimage, $image, 0, 0, 0, 0, $newwidth, $newheight,$row['width'], $row['height']);
    header("Content-type: image/jpeg");
    imagejpeg($newimage);
    die;
    }
header("Content-type: $filetype");

echo ($content);

You can do a php script that can resize the images in the fly and use it something like this 你可以做一个PHP脚本,可以动态调整图像大小,并使用它这样的东西

/image-resizer.php?source=path-to-the-image-here&width=x&height=x /image-resizer.php?source=path-to-the-image-here&width=x&height=x

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM