Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    May 2015
    Posts
    13
    Member #
    49985

    create thumbnails from images in PHP

    if(preg_match('/[.](jpg)$/', $filename)) {
    $im = imagecreatefromjpeg($file . $filename);
    } else if (preg_match('/[.](gif)$/', $filename)) {
    $im = imagecreatefromgif($file . $filename);
    } else if (preg_match('/[.](png)$/', $filename)) {
    $im = imagecreatefrompng($file . $filename);
    }

    $ox = imagesx($im);
    $oy = imagesy($im);

    $nx = $final_width_of_image;
    $ny = floor($oy * ($final_width_of_image / $ox));

    $nm = imagecreatetruecolor($nx, $ny);

    imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);

    imagejpeg($nm, $thumnailDir . $filename,100);
    $tn = '<img src="' . $thumnailDir . $filename . '" alt="image" />';
    $tn .= '<br />Congratulations. Your file has been successfully uploaded, and a thumbnail has been created.';
    echo $tn;


    Here is the code m using for creating a thumbnail image... but it returns me an image of 0 bytes... can any one help me with this where I am making mistake?

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,688
    Member #
    5580
    Liked
    717 times
    Does it work with JPG but not any other type? Or does it fail with all types?

    And when it shows you the image at the end, view the HTML and see what is in the img src line


  4. #3
    Junior Member
    Join Date
    May 2015
    Posts
    13
    Member #
    49985
    Quote Originally Posted by mlseim View Post
    Does it work with JPG but not any other type? Or does it fail with all types?

    And when it shows you the image at the end, view the HTML and see what is in the img src line
    Yeah i have tried with all type of image extensions but result is same that is image of 0 byte.

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,688
    Member #
    5580
    Liked
    717 times
    Simplify the script just for testing ... see if it can do the simplest thing first ...

    Like this:
    PHP Code:

    // hard-code a link to a real JPG photo ...
    $filename="myphoto.jpg";

            
    $im imagecreatefromjpeg($filename);

        
    $ox imagesx($im);
        
    $oy imagesy($im);
         
        
    $nx $final_width_of_image;
        
    $ny floor($oy * ($final_width_of_image $ox));
         
        
    $nm imagecreatetruecolor($nx$ny);
      
        
    imagecopyresized($nm$im0,0,0,0,$nx,$ny,$ox,$oy);
        
        
    imagejpeg($nm$thumnailDir $filename,100);
        
    $tn '<img src="' $thumnailDir $filename '" alt="image" />';
        
    $tn .= '<br />Congratulations. Your file has been successfully uploaded, and a thumbnail has been created.';
        echo 
    $tn

    See if that works.


  6. #5
    Junior Member
    Join Date
    May 2015
    Posts
    13
    Member #
    49985
    Thanks Mlseim. Let me try this I hope it will work fro me as well.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:55 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com