开发者

ImageCreate() error Size Issue

开发者 https://www.devze.com 2023-04-12 00:04 出处:网络
I created images in php to display in my home page ImageCreate(200, 800); // very simple and working. No sizing it is an issue for me.

I created images in php to display in my home page

ImageCreate(200, 800); // very simple and working. No sizing it is an issue for me.

Is there a way to just set the size of this image so that the width of the image always expands to a percentage of 开发者_StackOverflowthe page. eg. If I put 4 images on my page each image will just take up 25% of the page width. I tried to ImageCreate(25%,100%) but it does not work.


You can get the browser viewport width and height with javascript and submit them using AJAX to the image creation script. Have the AJAX return the path to the image and then place the image where you want it on the page.

$(document).ready(function() {  
    $.ajax({
        type: 'POST',
        url: 'ajax/makeimage.php',
        data: $.param({
            width: $(window).width(),
            height: $(window).height()
        }),
        success: function(data) {
            $('#where-your-image-goes').html(data);
        }
    });
});


I just extend the Post from Ben

The jQuery Part:

$(document).ready(function() {  
    $.ajax({
        type: 'POST',
        url: 'ajax/makeimage.php',
        data: $.param({
            width: $(window).width(),
            height: $(window).height()
        }),
        success: function(data) {
           $('#where-your-image-goes').html(data);
        }
    });
});

the PHP Part in makeImage.php

$oneImageWidth  = intval($_POST['width'] / 4); /* the 25% */
$oneImageHeight = intval($_POST['height']);
ImageCreate(25%,100%);

?>

Hope it helps


If it's just 4 color blocks with a width of 25%, you could just use 4 divs and set the background color to the one you want and the width to 25%.


PHP is a server side language so it has no idea of what size the browser is ... you could use CSS and set the image width to a percentage - but this might distort the image if you create it too small .... just out of interest why do you create the images each time you display the page ?

This might help you -> http://unstoppablerobotninja.com/entry/fluid-images

0

精彩评论

暂无评论...
验证码 换一张
取 消