Image Creator?

Discussion in 'PHP' started by henry, Dec 22, 2005.

  1. #1
    Hi every body.
    I don't know how I can upload a picture and after that it would change to dimension which I need to show in HTML.
    I have many sources but they all could create a photo figuratively.
    I mean I wanted to upload for example JPG file and it changes to new dimension, new size, new file and it remove ex-file or rewrite it.

    I have this source but it made an Images figuratively .(I don't need any uploaded source .)
    Thank you.


    <?php
    // File and new size
    $filename = '1.jpg';
    $percent = 0.5;

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

    // Get new sizes
    list($width, $height) = getimagesize($filename);
    $newwidth = $width * $percent;
    $newheight = $height * $percent;

    // Load
    $thumb = imagecreate($newwidth, $newheight);
    $source = imagecreatefromjpeg($filename);

    // Resize
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    // Output
    imagejpeg($thumb);
    ?>
     
    henry, Dec 22, 2005 IP
  2. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The uploader is a different section

    Here

    for the form, a multiple upload

    <form action="thank_you.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <table width="700" border="1" cellpadding="3" cellspacing="1">
    <tr>
    <td colspan="2"><strong>Upload The Files </strong></td>
    </tr>
    <tr>
    <td width="250">Select the First File:</td>
    <td><input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
    </tr>
    <tr>
    <td width="250">Select the Second file:</td>
    <td><input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
    </tr>
    <tr>
    <td width="250">Select the Third file:</td>
    <td><input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
    </tr>
    <tr>
    <td align="center" colspan="2"><input type="submit" name="Submit" value="Upload" />
      <input type="reset" name="Reset" value="Clear" /></td>
    </tr>
    
    </table>
    PHP:
    and for the upload
    this is the fun part

    
    <?php
    //location will be uploads/filename.ext
    //for example upload/cartoon.gif
    $path1= "uploads/".$HTTP_POST_FILES['ufile']['name'][0];
    $path2= "uploads/". $region ."/".$HTTP_POST_FILES['ufile']['name'][1];
    $path3= "uploads/". $region ."/".$HTTP_POST_FILES['ufile']['name'][2];
    
    //Move the files from temp to the folder, move is better
    move_uploaded_file($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
    move_uploaded_file($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
    move_uploaded_file($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);
    
    //$HTTP_POST_FILES['ufile']['name'] = file name
    //$HTTP_POST_FILES['ufile']['size'] = file size
    
    //add this to change the size
    //$HTTP_POST_FILES['ufile']['type'] = type of file
    
    echo "The following files have been uploaded";
    echo "<br>";
    
    echo "First File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>";
    echo "<P>";
    
    echo "Second File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>";
    echo "<P>";
    
    echo "Third File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>";
    echo "<p>";
    
    echo "<a href='main.php'>Click here</a> to go back, to upload another file.";
    
    ?>
    
    any problems, let us know
    
    PHP:
     
    onlyican.com, Dec 22, 2005 IP
  3. henry

    henry Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you dear friend.
    But as I said before ...I need a source which after these files were uploaded. It can change the size of them.
    For example we have an image test. Jpg (width='500' height='200' size='500kb') to upload.
    But I want when it uploaded it would change it to test. Jpg (width='50' height='20' size='50kb').
    Now you know what I mean.
    I think it needs GD libraries functions.
    Thank you very much.
     
    henry, Dec 22, 2005 IP
  4. Djohn

    Djohn Peon

    Messages:
    75
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I came across a pretty impressive alternative to actual resizing and saving, earlier today: phpThumb

    This differs from traditional resizing by just doing it on the fly, and never saving the file. What you do is, you call the image by a slightly different url:
    Example: phpThumb.php?src=images/pic1.jpg&w=50&h=20

    As you can see, you define the size right there in the url. I tried it out and it works just fine without ever having to do any complicated code. You just upload the files and it runs perfectly. Now, you can always change the config to your needs, if necessary.
     
    Djohn, Dec 22, 2005 IP
  5. henry

    henry Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi guys.i found it finally.
    form.::3.php===
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form action="4.php" method="post" enctype="multipart/form-data" name="form1">
      <table width="100%"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><input type="text" name="text"></td>
        </tr>
        <tr>
          <td><input type="file" name="file"></td>
        </tr>
        <tr>
          <td><input type="submit" name="Submit" value="Submit"></td>
        </tr>
      </table>
    </form>
    </body>
    </html>
    
    HTML:
    Action

    <?php
    mysql_connect("localhost","root","");
    mysql_select_db(test) or die("u");
    $r=$_FILES['file']['tmp_name'];
    $t=$_FILES['file']['name'];     
    $dir="images/car/$t";
        move_uploaded_file($r,"$dir"); 
                   $ins = "INSERT INTO `1` ( `id` , `address` ) VALUES ('', '$t');";
                   $insert = mysql_query($ins)or die (mysql_error());
    $thumbsize=60;
       $imgfile = "$dir";
       header('Content-type: image/jpeg');
       list($width, $height) = getimagesize($imgfile);
       $imgratio=$width/$height;
       if ($imgratio>1){
         $newwidth = $thumbsize;
         $newheight = $thumbsize/$imgratio;}
       else{
         $newheight = $thumbsize;
         $newwidth = $thumbsize*$imgratio;}
       $thumb = ImageCreateTrueColor($newwidth,$newheight);
       $source = imagecreatefromjpeg($imgfile);
       imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    imagejpeg($thumb,"$dir",100);
    header("location:3.php");
    ?>
    HTML:
     
    henry, Jan 12, 2006 IP