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 9 of 9
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts

    out an image after imagecopyresampled

    Hi;

    I am trying to output an image after imagecopyresampled, but it doesn't display any image on browser, could you tell me why, please.



    it just out some thing like following:

    ����JFIF��



    My original image is 36KB and 900*900
    and i want them become to 18kb and 100&100


    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <META HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8">
    </head>
    <body>

    <?php
    function resizeImage($originalImage,$toWidth,$toHeight){
        
        
    // Get the original geometry and calculate scales
        
    list($width$height) = getimagesize($originalImage);
        
    $xscale=$width/$toWidth;
        
    $yscale=$height/$toHeight;
        
        
    // Recalculate new size with default ratio
        
    if ($yscale>$xscale){
            
    $new_width round($width * (1/$yscale));
            
    $new_height round($height * (1/$yscale));
        }
        else {
            
    $new_width round($width * (1/$xscale));
            
    $new_height round($height * (1/$xscale));
        }

        
    // Resize the original image
        
    $imageResized imagecreatetruecolor($new_width$new_height);
        
    $imageTmp     imagecreatefromjpeg ($originalImage);
        
    imagecopyresampled($imageResized$imageTmp0000$new_width$new_height$width$height);

        return 
    $imageResized;
    }
    ?> 

    <?php
      $image
    resizeImage("upload/testimage.jpg",200,200);
      
    imagejpeg($imagenull100);

      
    //$info = getimagesize("upload/testimage.jpg");
      //print_r($image);
    ?>

    </body>
    </html>
    Last edited by kamkam; 08-22-2009 at 09:28 AM.

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    When PHP makes an image then outputs it, it generates a seperate file from any HTML. Remove all HTML coding and spaces on that page and add this somewhere in the PHP coding before any output. It changes the page type to an image:

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

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    but it still does not display the image, after i added the header on it, just shows a square, and there is a cross inside the square.

    and also if write like <img src="upload/testimage.jpg">, it give me the same result as above, but if i write <img src="upload/testimage.jpg"> to another page, it will display the image.






    PHP Code:
    <?php
    header
    ('Content-type:image/jpeg'); 
    ?>
    <?php 
    function resizeImage($originalImage,$toWidth,$toHeight){ 
         
        
    // Get the original geometry and calculate scales 
        
    list($width$height) = getimagesize($originalImage); 
        
    $xscale=$width/$toWidth
        
    $yscale=$height/$toHeight
         
        
    // Recalculate new size with default ratio 
        
    if ($yscale>$xscale){ 
            
    $new_width round($width * (1/$yscale)); 
            
    $new_height round($height * (1/$yscale)); 
        } 
        else { 
            
    $new_width round($width * (1/$xscale)); 
            
    $new_height round($height * (1/$xscale)); 
        } 

        
    // Resize the original image 
        
    $imageResized imagecreatetruecolor($new_width$new_height); 
        
    $imageTmp     imagecreatefromjpeg ($originalImage); 
        
    imagecopyresampled($imageResized$imageTmp0000$new_width$new_height$width$height); 

        return 
    $imageResized

    ?>  

    <?php 
      $image
    resizeImage("upload/testimage.jpg",200,200); 
      
    imagejpeg($imagenull100); 

      
    //$info = getimagesize("upload/testimage.jpg"); 
      //print_r($image); 
    ?>

  • #4
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    and if i change as following, it display nothing, even the litter square and cross disapear away

    PHP Code:
    <?php 
      $image
    resizeImage("upload/testimage.jpg",200,200); 
      
    imagejpeg($image'upload/testimage.jpg'100); 

     
    ?>
    Last edited by kamkam; 08-23-2009 at 12:53 AM.

  • #5
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    PHP Code:
    <?php

    header
    ('Content-type:image/jpeg'); 
     
    function 
    resizeImage($originalImage,$toWidth,$toHeight){ 
         
        
    // Get the original geometry and calculate scales 
        
    list($width$height) = getimagesize($originalImage); 
        
    $xscale=$width/$toWidth
        
    $yscale=$height/$toHeight
         
        
    // Recalculate new size with default ratio 
        
    if ($yscale>$xscale){ 
            
    $new_width round($width * (1/$yscale)); 
            
    $new_height round($height * (1/$yscale)); 
        } 
        else { 
            
    $new_width round($width * (1/$xscale)); 
            
    $new_height round($height * (1/$xscale)); 
        } 

        
    // Resize the original image 
        
    $imageResized imagecreatetruecolor($new_width$new_height); 
        
    $imageTmp     imagecreatefromjpeg ($originalImage); 
        
    imagecopyresampled($imageResized$imageTmp0000$new_width$new_height$width$height); 

        return 
    $imageResized


     
      
    $imageresizeImage("upload/testimage.jpg",200,200); 
      
    imagejpeg($imagenull100); 

      
    //$info = getimagesize("upload/testimage.jpg"); 
      //print_r($image); 

     
    ?>
    No spaces, pure PHP block.

  • #6
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    an image comes out now, but it is strange that the image is not the one i want.

    it comes out an image with some text of the "A Simple Text String" and the background color is black.

    But in my folder upload, the image testimage.jpg is a buillding

  • #7
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    an image comes out now, but it is strange that the image is not the one i want.
    it comes out an image with some text of the "A Simple Text String" and the background color is black.

    But in my folder upload, the image testimage.jpg is a buillding

  • #8
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    You should take a look at my Dynamic Image Resizing in the snippet section. Will solve all your problems.
    Last edited by Element; 08-24-2009 at 02:16 AM.

  • #9
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can generate it
    Cheap Web Hosting || Web Hosting
    by using any HTML.


  •  

    Posting Permissions

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