Re: Automatic Image Upload with Thumbnails

I just can't get this mod to work at all http://etern.mine.nu/uploadimg.php it results in a blank page. Any ideas? I have loaded the gd-library succesfully. I've download another mod also http://etern.mine.nu/gallery_upload.php (you're free to try) but when I upload a picture it's the picture isn't there. Hmm maybe I should use an .htaccess file...

102 (edited by Peter 2007-08-20 02:22)

Re: Automatic Image Upload with Thumbnails

How can I use this code for just the "avatar" upload?

For avatar upload I now use this solution by thame^, but the picture quality is much better with Koos' solution.

I'd like to use Koos' code in profile.php for the avatar upload, but with the regular avatar naming method and regular img/avatars folder - although it would be a nice improvement if the originals were saved as well, so maybe add an img/avatars/thumb folder?

This was thame^'s code:

        if (is_uploaded_file($uploaded_file['tmp_name']))
        {
            $allowed_types = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png');
            if (!in_array($uploaded_file['type'], $allowed_types))
                message($lang_profile['Bad type']);

            // Determine type
            $extensions = null;
            if ($uploaded_file['type'] == 'image/gif')
                $extensions = array('.gif', '.jpg', '.png');
            else if ($uploaded_file['type'] == 'image/jpeg' || $uploaded_file['type'] == 'image/pjpeg')
                $extensions = array('.jpg', '.gif', '.png');
            else
                $extensions = array('.png', '.gif', '.jpg');

            // Move the file to the avatar directory. We do this before checking the width/height to circumvent open_basedir restrictions.
            if (!@move_uploaded_file($uploaded_file['tmp_name'], $pun_config['o_avatars_dir'].'/'.$id.'.tmp'))
                message($lang_profile['Move failed'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');

            // Now check the width/height
            list($width, $height, $type,) = getimagesize($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
            if (empty($width) || empty($height) || $width > $pun_config['o_avatars_width'] || $height > $pun_config['o_avatars_height'])
            {

                // Attempt to resize if GD is installed with support for the uploaded image type, as well as JPG for the output
                $check_type = str_replace(array(1, 2, 3), array('IMG_GIF', 'IMG_JPG', 'IMG_PNG'), $type);
                if (extension_loaded('gd') && imagetypes() & constant($check_type) && imagetypes() & IMG_JPG)
                {

                    // Load the image for processing
                    if ($type == 1) $src_img = @imagecreatefromgif($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
                    elseif ($type == 2) $src_img = @imagecreatefromjpeg($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
                    elseif ($type == 3) $src_img = @imagecreatefrompng($pun_config['o_avatars_dir'].'/'.$id.'.tmp');

                    if ($src_img)
                    {

                        // Figure out new image dimensions based on the maximum width
                        $new_w = $pun_config['o_avatars_width'];
                        $ratio = $height * $new_w;
                        $new_h = $ratio / $width;

                        // Do the new dimensions, based on the maximum width, fit the maximum height? If not, recalculate
                        if ($new_h > $pun_config['o_avatars_height'])
                        {
                            $new_h = $pun_config['o_avatars_height'];
                            $ratio = $width * $new_h;
                            $new_w = $ratio / $height;
                        }

                        // Resize the image
                        $new_img = imagecreatetruecolor($new_w, $new_h);
                        imagecopyresized($new_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, $width, $height);

                        // Delete the old image and write the newly resized one
                        @unlink($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
                        imagejpeg($new_img,$pun_config['o_avatars_dir'].'/'.$id.'.tmp');

                        // Set the extension to JPG, since that's what the resized image is now
                        $extensions[0] = '.jpg';
                    }

                    // Something went wrong while attempting to load the image for processing
                    else
                    {
                        @unlink($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
                        message('An unexpected error occured while attempting to resize the image.');
                    }
                }

                // No GD installed or image type not supported; can't resize
                else
                {
                    @unlink($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
                    message($lang_profile['Too wide or high'].' '.$pun_config['o_avatars_width'].'x'.$pun_config['o_avatars_height'].' '.$lang_profile['pixels'].'.');
                }
            }
            else if ($type == 1 && $uploaded_file['type'] != 'image/gif')    // Prevent dodgy uploads
            {
                @unlink($pun_config['o_avatars_dir'].'/'.$id.'.tmp');
                message($lang_profile['Bad type']);
            }

            // Make sure the file isn't too big
            if (filesize($pun_config['o_avatars_dir'].'/'.$id.'.tmp') > $pun_config['o_avatars_size'])
                message($lang_profile['Too large'].' '.$pun_config['o_avatars_size'].' '.$lang_profile['bytes'].'.');

            // Delete any old avatars and put the new one in place
            @unlink($pun_config['o_avatars_dir'].'/'.$id.$extensions[0]);
            @unlink($pun_config['o_avatars_dir'].'/'.$id.$extensions[1]);
            @unlink($pun_config['o_avatars_dir'].'/'.$id.$extensions[2]);
            @rename($pun_config['o_avatars_dir'].'/'.$id.'.tmp', $pun_config['o_avatars_dir'].'/'.$id.$extensions[0]);
            @chmod($pun_config['o_avatars_dir'].'/'.$id.$extensions[0], 0644);
        }
        else
            message($lang_profile['Unknown failure']);

        // Enable use_avatar (seems sane since the user just uploaded an avatar)
        $db->query('UPDATE '.$db->prefix.'users SET use_avatar=1 WHERE id='.$id) or error('Unable to update avatar state', __FILE__, __LINE__, $db->error());

        redirect('profile.php?section=personality&id='.$id, $lang_profile['Avatar upload redirect']);
    }

    $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
    $required_fields = array('req_file' => $lang_profile['File']);
    $focus_element = array('upload_avatar', 'req_file');
    require PUN_ROOT.'header.php';

?>
<div class="blockform">
    <h2><span><?php echo $lang_profile['Upload avatar'] ?></span></h2>
    <div class="box">
        <form id="upload_avatar" method="post" enctype="multipart/form-data" action="profile.php?action=upload_avatar2&id=<?php echo $id ?>" onsubmit="return process_form(this)">
            <div class="inform">
                <fieldset>
                    <legend><?php echo $lang_profile['Upload avatar legend'] ?></legend>
                    <div class="infldset">
                        <input type="hidden" name="form_sent" value="1" />
                        <!--<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $pun_config['o_avatars_size'] ?>" />-->

It does what I need, but the resized pictures are really ugly. Koos' code produces a much nicer result. How can I improve thame^'s code with bits from Koos?

I suspect the problem is in the resize method. thame^ uses $ratio, Koos uses $zoom. How can I use the $zoom method in thame^'s code? I'm not a PHP-coder, so this is hard for me to figure out.

103 (edited by MattF 2007-08-20 14:35)

Re: Automatic Image Upload with Thumbnails

Peter wrote:

I suspect the problem is in the resize method. thame^ uses $ratio, Koos uses $zoom. How can I use the $zoom method in thame^'s code? I'm not a PHP-coder, so this is hard for me to figure out.

zoom/ratio are variables. They are irrelevant to the rescaling method and quality as such. It's the imagecreate parts of the script that you need to concentrate upon. Changing imagecopyresized to imagecopyresampled *may* also help.

Edit: Btw, this question would be best placed in the thread for the avatar mod itself, rather than this thread.

104 (edited by thame^ 2007-12-18 00:25)

Re: Automatic Image Upload with Thumbnails

MattF wrote:

Changing imagecopyresized to imagecopyresampled *may* also help.

This is the correct answer!  I don't know what I was thinking when I used imagecopyresized back then, but changing it to imagecopyresampled will definitely improve the quality.  I've updated the code on my site (coloured too).  Sorry about that!

I should probably turn all that into a mod, but I'm lazy and I don't know how.  If anyone's willing to do it for me, please do.

EDIT: This was turned into a proper mod some time ago.  Please refer to http://punbb.org/forums/viewtopic.php?id=16883

105

Re: Automatic Image Upload with Thumbnails

thame^ wrote:
MattF wrote:

Changing imagecopyresized to imagecopyresampled *may* also help.

This is the correct answer!  I don't know what I was thinking when I used imagecopyresized back then, but changing it to imagecopyresampled will definitely improve the quality.  I've updated the code on my site (coloured too).  Sorry about that!

I should probably turn all that into a mod, but I'm lazy and I don't know how.  If anyone's willing to do it for me, please do.

You can achieve an even better quality (quality of the 'Automatic Image Upload' mod) by replacing:

                        imagejpeg($new_img,$pun_config['o_avatars_dir'].'/'.$id.'.tmp');

with

                        imagejpeg($new_img,$pun_config['o_avatars_dir'].'/'.$id.'.tmp',85);

on thame^'s code.

The 85 sets the quality. This can be anything between 1-100. I chose 85 since this gives a good quality and still gives a small image file size. Using 100 the file size becomes unnecessarily large.

Nice script by the way.

106

Re: Automatic Image Upload with Thumbnails

Thanks thame^ and Koos. It now does exactly what I needed. Just have to customize the interface a bit. :-)

107

Re: Automatic Image Upload with Thumbnails

Mod does not work for me. Everything seems to work, I even got "Result
Image uploaded successfully.
Image thumbnail created successfully."

But in reality - upload folder is empty and posted code is not working becouse of this...

What could be problem that mod do not upload files to "upload" folder?

Re: Automatic Image Upload with Thumbnails

Ahmed: Is your upload folder writable by PHP (I'm not familiar with this mod, but that might be your issue)?

Looking for a certain modification for your forum? Please take a look here before posting.

109

Re: Automatic Image Upload with Thumbnails

pogenwurst wrote:

Ahmed: Is your upload folder writable by PHP (I'm not familiar with this mod, but that might be your issue)?

My knowledge is too weak to understand what do You mean...
I chmoded "upload" and "thumbs" to 777 (as it was said in readme.txt).

110

Re: Automatic Image Upload with Thumbnails

Ahmed wrote:

Mod does not work for me. Everything seems to work, I even got "Result
Image uploaded successfully.
Image thumbnail created successfully."

But in reality - upload folder is empty and posted code is not working becouse of this...

What could be problem that mod do not upload files to "upload" folder?

Hi Ahmed. Can you please get the following info for me - by creating a small file (e.g. test.php) containing:

        <? phpinfo() ?>

    and looking at it using a web browser:

*PHP Version
*safe_mode
*safe_mode_gid

*file_uploads
*max_execution_time
*memory_limit
*post_max_size
*upload_max_filesize

*GD Support
*GD Version

Also:

Did you change anything in the uploadimg_config.php file?

Have you successfully used other image upload mods on your forum before?

111

Re: Automatic Image Upload with Thumbnails

This ir info:

PHP Version 4.3.9

*safe_mode
*safe_mode_gid - both off/off
file_uploads on/on
max_execution_time 30/30
memory_limit 8M 8M
post_max_size 8M 8M
upload_max_filesize 2M 2M
GD Support  enabled 
GD Version  bundled (2.0.28 compatible) 
-----------
So I guess there is no problem.

I use just BBcode [img] and it works. Did not use any other upload mod.

I changed that file (added usergroups, and others).
Here is my file:

<?php

  /*****************************************************
  ** Script configuration
  *****************************************************/

$idir = "uploads/";   // Path To Images Directory
$tdir = "uploads/thumbs/";   // Path To Thumbnails Directory

$twidth = "400";   // Maximum Width For Thumbnail Images - default = 150
$theight = "400";   // Maximum Height For Thumbnail Images - default = 150
$size_limit = "no"; // **** if "yes" there will be a file size limit for uploaded files
$limit_size = "600"; // file size limit in KB - default = 200

$allow_resize_option = "1"; // allow = 1 ; disallow = 0

$resize_images_above_limit = "yes"; // if "yes" images exceeding 'limit_size' will be automatically resized to 640x480
                                    // - must set $size_limit = "no" for this to work

$allow_jpg_uploads = "1"; // allow = 1 ; disallow = 0
$allow_png_uploads = "1"; // allow = 1 ; disallow = 0
$allow_gif_uploads = "1"; // allow = 1 ; disallow = 0

// ** Gallery settings
$images_per_page = "20"; // number of images displayed per page in the gallery
$images_per_row = "4"; 
$display_img_box = "0"; // allow = 1 ; disallow = 0


  /*****************************************************
  ** Permission setting
  *****************************************************/

$Allow_Uploads = array();
//
// Listed below are user groups that are are allowed to upload images.
//
// $Allow_Uploads[] = "MY_USERGROUP";
//
$Allow_Uploads[] = "Administrators";
$Allow_Uploads[] = "Moderators";
$Allow_Uploads[] = "Uploaders";
$Allow_Uploads[] = "Members";
/*
The permission setting allows you to have full control over who can upload images.

If you want all members to be able to upload images, just add the following line:
$Allow_Uploads[] = "Members";

To ban a certain user from uploading images, just move the user to an user group not
included in the  $Allow_Uploads array.

For those who do not know how to create new user groups:
Log in as administrator and go to Administration->User groups->Add new group
*/


  /*****************************************************
  ** Statistics setting
  *****************************************************/

$Allow_Stats = array();
//
// Listed below are user groups that are are allowed to view upload statistics.
//
// $Allow_Stats[] = "MY_USERGROUP";
//
$Allow_Stats[] = "Administrators";
$Allow_Stats[] = "Moderators";
$Allow_Stats[] = "Uploaders";
$Allow_Stats[] = "Members";
//$Allow_Stats[] = "Uploaders";
//$Allow_Stats[] = "Members";


  /*****************************************************
  ** Delete setting
  *****************************************************/

$Allow_Delete = array();
//
// Listed below are user groups that are allowed to delete their own uploaded images.
// Note: Only Administrators can delete images of another user
//
// $Allow_Delete[] = "MY_USERGROUP";
//

$Allow_Delete[] = "Administrators";
$Allow_Delete[] = "Moderators";
$Allow_Delete[] = "5. pakâpes foruma dalîbnieki";
$Allow_Delete[] = "6. pakâpes foruma dalîbnieki";
$Allow_Delete[] = "7. pakâpes foruma dalîbnieki";
$Allow_Delete[] = "8. pakâpes foruma dalîbnieki";
$Allow_Delete[] = "9. pakâpes foruma dalîbnieki";
$Allow_Delete[] = "10. pakâpes foruma dalîbnieki";
//$Allow_Delete[] = "Uploaders";
//$Allow_Delete[] = "Members";


?>

112 (edited by Koos 2007-09-09 08:09)

Re: Automatic Image Upload with Thumbnails

Ahmed wrote:

So I guess there is no problem.

I use just BBcode [url]and it works. Did not use any other upload mod.
...

Everything looks alright - except your php version is little bit outdated. Can you try to use version 1.1.1 of this mod - and then see if both the /uploads and /uploads/thumbs directories remain empty after trying to upload an image.

113

Re: Automatic Image Upload with Thumbnails

Tried vesion 1.1.1:::::::::::

Result
ERROR: Unable to upload image.

:-((((((((

114

Re: Automatic Image Upload with Thumbnails

Ahmed wrote:

Tried vesion 1.1.1:::::::::::

Result
ERROR: Unable to upload image.

:-((((((((

I think it would be best if you contact your server administrator and ask them to upgrade to the latest version of php and make sure that GD is configured properly.

Also you can try out one more thing: Use version 1.3.1 of this mod and try to upload an image that is smaller than the thumbnail size (as set in the uploadimg_config.php file). Then check with a ftp program to see if the file was uploaded to the /uploads and /uploads/thumbs folders.

115 (edited by iatbm 2007-09-13 01:28)

Re: Automatic Image Upload with Thumbnails

Huh anyone encountered the problem when quoting post with image thumbnail ?

It changes from [img] ro [url]when quoting the post with thumb

Well maybe this is not because of mod wink I just found out that it is punbb thing but it is annoying that it shows thumb when you click on link in quoted post. Oh well .... have to look elsewhere.

I will just add AWESOME MOD !

116

Re: Automatic Image Upload with Thumbnails

I want to show a picture of the person that's logged in on a new page I'm trying to put together (myaccount.php).

I've tried copying code from profile.php and viewtopic.php, but can't get anything to work.

This line apparently depends on lots of other code in profile.php:

<img src="<?php echo $pun_config['o_avatars_dir'].'/'.$id.'.'.$avatar_format ?>" <?php echo $img_size[3] ?> alt="" />

I've tried including other code snippets with '$avatar_format' etc. in myaccount.php, but nothing works.

What is the simplest way to call a picture in a new php file within PunBB? Especially the file format part (jpg, gif, png) is a mystery to me.

117

Re: Automatic Image Upload with Thumbnails

Maybe this helps you:
http://punbb.org/forums/viewtopic.php?id=15045

FluxBB - v1.4.8

118 (edited by Peter 2007-10-22 22:32)

Re: Automatic Image Upload with Thumbnails

Excellent suggestion lie2815!

After some puzzling I now have this to show the picture of the logged-in person on my alternative myaccount.php page:

$result = $db->query('SELECT * FROM users WHERE id = '.$pun_user['id']) or error('Unable to fetch user data', __FILE__, __LINE__, $db->error());
$row = $db->fetch_assoc($result);

        if ($pun_user['id'])
        {
        if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$pun_user['id'].'.gif'))
        $picture = '<img src="'.$pun_config['o_avatars_dir'].'/'.$pun_user['id'].'.gif" '.$img_size[3].' alt="" />';
        else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$pun_user['id'].'.jpg'))
        $picture = '<img src="'.$pun_config['o_avatars_dir'].'/'.$pun_user['id'].'.jpg" '.$img_size[3].' alt="" />';
        else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$pun_user['id'].'.png'))
        $picture = '<img src="'.$pun_config['o_avatars_dir'].'/'.$pun_user['id'].'.png" '.$img_size[3].' alt="" />';
        else
        $picture = '<img src="'.$pun_config['o_avatars_dir'].'/nopicture.png"'.$img_size[3].' alt="" />';
        }

?>
<h2><? echo $row['firstname']; ?>'s Account</h2>
<? echo $picture; ?>
...

Happy!

119

Re: Automatic Image Upload with Thumbnails

Glad it helped. Thats what this forum is for wink

FluxBB - v1.4.8

120

Re: Automatic Image Upload with Thumbnails

I have some strange problem with this mod - it does not show me real path to mz pictures, but ads some tag: www.something.trt/exec/upload... instead of exec it should be "forum". Any idea?

121

Re: Automatic Image Upload with Thumbnails

what is the image path set to in admistation panel.??

Sorry. Unactive due to personal life.

122

Re: Automatic Image Upload with Thumbnails

Well, if you think in forum admin panel, i cannot find what you've asked me.

MAybe i didn't explain problem ok. I can see pictures, but in a small box under them - with img tags, i get that problem that i mentioned.

123

Re: Automatic Image Upload with Thumbnails

I think theres a bug in Automatic Image Upload 1.3.2.

If I define the Group Members with permissions in uploadimg_config.php it also gives the same permission to the Group New Members. My guess is that the script is not doing an exact match for the group.

124

Re: Automatic Image Upload with Thumbnails

I managed to solve a problem with $forumurl  variable in script.

125 (edited by Koos 2007-10-28 10:18)

Re: Automatic Image Upload with Thumbnails

dboling wrote:

I think theres a bug in Automatic Image Upload 1.3.2.

If I define the Group Members with permissions in uploadimg_config.php it also gives the same permission to the Group New Members. My guess is that the script is not doing an exact match for the group.

The title 'New member' is not a group, but a rank. Go to the 'User groups' link in the Admin menu to create new groups.