THUMBS -> imageXXX / header ("Content-type: mime_type");
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: THUMBS -> imageXXX / header ("Content-type: mime_type");

  1. #1
    Join Date
    Nov 2004
    Posts
    186

    THUMBS -> imageXXX / header ("Content-type: mime_type");

    I have images in my server and I´d like to "create" thumbnails.
    I tried to resize the image but it appears blured and strange.

    I want to do that then because the image looks perfect when I do it.

    Code:
    function Thumb($photo, $new_width)
    {
    $source = imagecreatefromstring(file_get_contents($photo));
    $thumb = imagecreatetruecolor($new_width, $new_height);
    imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 
    header ("Content-type: image/jpeg");
    imagejpeg("my_resized_img.jpg");
    }
    
    Thumb("images/pic139.jpg",150);
    When I run the code it works perfectly but JUST FOR ONE IMAGE (pic139.jpg).
    But what I want to do is that for all the images displayed in the page.
    Something like this:

    Code:
    Thumb("images/pic139.jpg",150);
    Thumb("images/pic140.jpg",150);
    Thumb("images/pic141.jpg",150);
    etc...

    How can I do that without having to create the thumbnail?
    The problem that I see is with the header ("Content-type: image/jpeg");

    Any ideas?

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,839

    Re: THUMBS -> imageXXX / header ("Content-type: mime_type");

    Rather than ask a bunch of questions, just try using the following instead. Name it thumbnail.php and pass path and width as parameters.

    PHP Code:
    <?php
    header
    ('Content-type: image/jpeg');
    $path = @$_GET['path'];
    $img_source imagecreatefromjpeg($path);
    list(
    $width$height) = getimagesize($path);

    $new_width = @$_GET['width'];
    $new_height = ($height $width) * $new_width;

    $img_output imagecreatetruecolor($new_width$new_height);
    imagecopyresampled($img_output$img_source0000$new_width$new_height$width$height);

    imagejpeg($img_output""100);
    imagedestroy($img_output);
    imagedestroy($img_source);
    ?>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Nov 2004
    Posts
    186

    Re: THUMBS -> imageXXX / header ("Content-type: mime_type");

    It worked. Thanks.
    Last edited by rogernem; October 27th, 2009 at 01:45 PM.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center