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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Location
    Utrecht, Holland
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    how to generate a thumbnail?

    How can I generate a thumbnail with script?
    PHP Code:
    <?php
    /* Start Verwerking */
    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        
    $ext            $_FILES['type'];
        
    $file_name        md5(rand(01000).'-'.time()).$ext.".jpg";
        
    $target_path    "../photo/".$_POST['album']."/".$file_name;
        
    $ar        = array();
        
    $ar[0]    = 'image/jpeg';
        
        
    $title            mysql_real_escape_string($_POST['title']);
        
    $description    mysql_real_escape_string($_POST['description']);
        
    $album            mysql_real_escape_string($_POST['album']);

        if(isset(
    $_POST['send'])){
            
    $fouten = array();
            if (empty(
    $_POST['title'])){
                
    $fouten[] = "Geen naam ingevuld!";
            }
            if(empty(
    $_POST['description'])){
                
    $fouten[] = "Geen beschrijving ingevuld!";
            }
            if(empty(
    $_POST['album'])){
                
    $fouten[] = "Geen album opgegeven!";
            }
            if(empty(
    $_FILES['file']['name'])){
                
    $fouten[] = "Geen foto geselecteerd!";
            }
            if(!
    in_array($_FILES['file']['type'],$ar)){
                
    $fouten[] = "Verkeerd bestandstype!";
            }
            
    $counter count($fouten);
            if(
    $counter 0){
            echo 
    "    <font color='#FF0000'>
                        <ol>
                            <font color='#000000'>De volgende velden zijn niet correct ingevuld:</font>
                            <li>"
    .join("</li>
                            <li>"
    $fouten)."</li>
                        </ol>
                    </font>"
    ;
            }
        }
        if(
    $counter == 0){
            if(
    in_array($_FILES['file']['type'],$ar)){            
                
    $sql "INSERT INTO photo_photo(id, title, description, album, file)
                VALUES ('','"
    .$title."', '".$description."', '".$album."', '".$file_name."')";
                
    mysql_query($sql);
                
    move_uploaded_file($_FILES['file']['tmp_name'], $target_path);
                echo 
    "<br>Foto is succesvol ge&uuml;pload en in het album geplaatst.<br>";
            }
        }
    }
    /* Einde Verwerking */
    $photo    "SELECT * FROM photo_photo";
    $photo    mysql_query($photo);
    $album    "SELECT * FROM photo_album ORDER BY id";
    $album    mysql_query($album);
    ?>
    <form name="photo_add" method="post" action="<?php $_SERVER['PHP_SELF'?>" enctype="multipart/form-data">
    <table>
        <tr>
            <td>Naam</td>
            <td><input type="text" name="title" size="45" /></td>
        </tr>
        <tr>
            <td>Beschrijving</td>
            <td><textarea name="description" cols="34"></textarea></td>
        </tr>
        <tr>
            <td>Album</td>
            <td>
                <select name="album">
                <?php
                
    while($album_rij mysql_fetch_array($album)){
                    
    ?>
                    <option value="<?php echo $album_rij[0?>"><?php echo $album_rij[1?></option>
                    <?php
                
    }
                
    ?>
                </select>
            </td>
        </tr>
        <tr>
            <td>Selecteer een foto</td>
            <td><input type="file" name="file" size="45" /></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" value="Foto toevoegen" name="send" /></td>
        </tr>
    </table>
    </form>
    FIA2008

  • #2
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post
    $big_file=$_FILES['file']['tmp_name'];
    $new_file='/tmp/thumbnail.jpg';

    copy($big_file, $new_file);

    $thumb_width=50;
    $thumb_height=35;

    $thumb = imagecreatetruecolor($thumb_width,$thumb_height);
    $source = imagecreatefromjpeg($big_file);
    imagecopyresized($thumb,$source,0,0,50,35,$thumb_width,$thumb_height,188,188);

    imagejpeg($thumb,$new_file);


  •  

    Tags for this Thread

    Posting Permissions

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