Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts

    how i can insert a resized image into HTML file?

    Hi;

    How i can insert an resized image into a html file, please.

    If i do like the following, it does not work. Could any one help, please.

    PHP Code:
    <?php
        
    function resizeImage($originalImage,$toWidth,$toHeight$maintain=true){ 
        
    //check that image exists
        
    if (!is_file($originalImage) || !is_readable($originalImage)) return false;
        
    // Get the original geometry and calculate scales 
        
    list($width$height) = getimagesize($originalImage); 
        if (
    $maintain) list($newWidth$newHeight) = ( (($toWidth/$toHeight) > ($width/$height)) ?array (intval(($toWidth $width/$height)), intval($toHeight)) : array (intval($toWidth), intval(($toHeight $height/$width))));
        
        
    // Resize the original image 
        
    $imageResized imagecreatetruecolor($newWidth$newHeight); 
        
    $imageTmp     imagecreatefromjpeg ($originalImage); 
        
    imagecopyresampled($imageResized$imageTmp0000$newWidth$newHeight$width$height); 
        return 
    $imageResized;
    }



    ?>

    <html>
    <body>
    I want the image sit under me.
    <?php
     $image
    =resizeImage("testme.jpg",200,200,"true"); //this one shows on the browser
     
    imagejpeg($imagenull20); 
    ?>

    </body>
    </html>
    Last edited by kamkam; 08-29-2009 at 12:45 PM.

  • #2
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    I don't understand the problem, you said the code does work? Then what's the issue?
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Sorry, the code does not work.

    when i open the website, it come out garbage and without the image and some text.
    Last edited by kamkam; 08-29-2009 at 12:50 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Image data cannot be combined with html. I believe that FF will actually take a source of base64 encoded data, but I wouldn't recommend that anyway.

    I haven't gone over this code, but at a glance it looks good. Its the html you'll need to remove.
    What you want is this file to serve as the image. So you will send an appropriate header indicating thats its an image. This case its a jpg image, if you want to dynamically choose you can retrieve the type with getimagesize on the original image (note that as long as you use imagejpeg it will be a jpeg).
    Than you call it as the source for the image in the html, not embedded with the html. Does that make sense?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    kamkam (08-30-2009)

  • #5
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    ok, after i removed the html off, i can see the image.

    But the problem for me how i can use the resized image to sit into a html file, like the following page:

    http://www.realestate.com.au/cgi-bin...any&cat=&o=def

    http://www.realestate.com.au/cgi-bin...&tm=1251545919


    After i removed the html, i can see the image.

    PHP Code:
    <?php
    header
    ('Content-type:image/jpeg');  

        function 
    resizeImage($originalImage,$toWidth,$toHeight$maintain=true){ 
        
    //check that image exists
        
    if (!is_file($originalImage) || !is_readable($originalImage)) return false;
        
    // Get the original geometry and calculate scales 
        
    list($width$height) = getimagesize($originalImage); 
        if (
    $maintain) list($newWidth$newHeight) = ( (($toWidth/$toHeight) > ($width/$height)) ?array (intval(($toWidth $width/$height)), intval($toHeight)) : array (intval($toWidth), intval(($toHeight $height/$width))));
        
        
    // Resize the original image 
        
    $imageResized imagecreatetruecolor($newWidth$newHeight); 
        
    $imageTmp     imagecreatefromjpeg ($originalImage); 
        
    imagecopyresampled($imageResized$imageTmp0000$newWidth$newHeight$width$height); 
        return 
    $imageResized;
    }



    ?>


    <?php
     $image
    =resizeImage("testme.jpg",200,200,"true"); //this one shows on the browser
     
    imagejpeg($imagenull20); 
    ?>
    Last edited by kamkam; 08-29-2009 at 02:02 PM.

  • #6
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Thanks, i have known how to do it already.

    I saved the above file as testimage.php, then in a html file, i will use the image as following:

    <img src='testimage.php?image=image.jpg' />


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •