SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Fifal's Avatar
    Join Date
    Oct 2005
    Location
    Windhoek Namibia
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation imagejpeg() problem

    Hi there

    The following code does not output the jpeg image in an html formatted page. ( Instead it only gives the binary code of that image ).

    PHP Code:
    // Specify source image
    $sourceImage "pics/plane.jpg";
                
    // Specify thumbnail height and width
    $thumbWidth 62;
    $thumbHeight 44;
                
    // Load the source image
    $original imagecreatefromjpeg($sourceImage);
                
    // Get the size of the original
    $dims getimagesize($sourceImage);
                
    // Create a blank thumbnail
    $thumb imagecreatetruecolor($thumbWidth$thumbHeight);
                
    // Copy a resized version of the original onto the thumbnail
    imagecopyresampled($thumb$original0,0,0,0$thumbWidth$thumbHeight$dims[0], $dims[1]);
                
    // Send the content header
    header("Content-type: image/jpeg");
                
    // Display the Image
    imagejpeg($thumb); 
    This works perfectly on a non-html formatted page.

    I think the problem lies with: header("Content-type: image/jpeg");

    Is there a way to use this function in an HTML formatted page ?

    Thanks

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes.


    use html to link to your php script.

    Code:
    <img src="your_script.php">


Bookmarks

Posting Permissions

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