Jump to content

PHP Image Handling Questions.


gergy008

Recommended Posts

Ok, A few questions here.

 

1. What function do I need to convert any file into PNG format?

 

2. Then how do I resize it to fit in a box 200 x 200, But make sure it keeps it's size ratio?

 

3. Then how do I get a file from the a form already made?

 

The form is

 

<form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post"> 
        <p class="nolink"> 
            <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>"> 
        </p>
        <p class="nolink"> 
            <label for="file">File to upload:</label> 
            <input id="file" type="file" name="file"> 
        </p> 
        <p class="nolink"> 
            <label for="submit">Press to...</label> 
            <input id="submit" type="submit" name="submit" value="Upload me!"> 
        </p> 
    </form>

 

Please don't do it for me, Just so I know how, I've never done image manipulation before, I'm new to that but old to everything else  :D

 

Thanks in advance!!

Link to comment
https://forums.phpfreaks.com/topic/185401-php-image-handling-questions/
Share on other sites

1. list of some applicable functions: imagecreatetruecolor, imagecreatefromjpeg, imagecreatefromgif, imagecreatefrompng, imagecopyresampled, imagepng

 

2.

 

<?php
$image = '/path/to/your-image.whatever';

#final image width;
$modwidth = 200;

#image options;
list ($width, $height, $type) = getimagesize( $image );

#do some math;
$diff = ($width / $modwidth);

#get new height;
$modheight = ($height / $diff);

#add width and height;
$image = imagecreatetruecolor($modwidth, $modheight);
?>

 

3. $_FILES['file']['name/tmp_name/size/etc'] (name, tmp_name, size, etc., are respective attributes to the $_FILES array .. use individually, not how i displayed.

<?php
$image = '/path/to/your-image.whatever';

#final image width;
$modwidth = 200;

#image options;
list ($width, $height, $type) = getimagesize( $image );

#do some math;
$diff = ($width / $modwidth);

#get new height;
$modheight = ($height / $diff);

#add width and height;
$image = imagecreatetruecolor($modwidth, $modheight);
?>

 

Thanks so much!! Just a question, Is it an absolute path ( "home/gergy008/public_html...etc etc" ) on that script? Or is it just like "images/image.png"

depends on your server configuration, but this should work:

 

<?php
$image = $_SERVER['DOCUMENT_ROOT'] .'/path/to/your/file.something';
?>

 

this might translate into:

 

C:/home/something/public_html/path/to/your/file.something

 

where something is often a username of some sorts.

 

i usually set my paths like this to avoid any complications.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.