Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: [MOD] Automatically resize image 2 (sNews 1.4)  (Read 8543 times)

ketut

  • Full Member
  • ***
  • Karma: 0
  • Posts: 115
    • Book Bali Hotels
[MOD] Automatically resize image 2 (sNews 1.4)
« on: September 10, 2006, 02:44:25 am »

we know that pictures are uploaded seperate from article itself.

* how can we upload pictures together with article or something similar?

so each article will have thumbnail image and one or more larger image.
thumbnail will display in short article list page/category page, while larger image will display on full article page. those images will not use again with another article.

if anyone have the module like above, please let me know.

thanks and i'm sorry for my bad english.

sincerely

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #1 on: September 10, 2006, 03:50:36 pm »

You can do that. It is just a matter of deciding how you want to organize your site's folder structure and what folder you want to put the extra images in. You could use the file transfer function mod located here - http://www.solucija.com/forum/viewtopic.php?id=949. It uploads most file types (including images) to another folder, and you can name that folder whatever you want. In your case, you would create your thumbnail and full-sized images and upload them. Then, when composing your article, you would insert the thumbnail image file-path where you want it to display and link it to the full image. When the article displays, the thumbnail will display, and clicking on it will load the full-sized image... in a new window if you set it to do so. This is the most basic way to do it. There are other 'cooler' ways to do it using techniques like Thickbox 2.0.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

ketut

  • Full Member
  • ***
  • Karma: 0
  • Posts: 115
    • Book Bali Hotels
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #2 on: September 20, 2006, 03:39:55 pm »

Thanks for your help mr. keyrocks but the link above did not work ;)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #3 on: September 20, 2006, 03:47:19 pm »

Quote from: ketut
Thanks for your help mr. keyrocks but the link above did not work ;)
Works now - for some reason an extra "9" got added to the end of the url string - removed it - OK now.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Fotrane

  • Newbie
  • *
  • Karma: 1
  • Posts: 28
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #4 on: September 20, 2006, 06:39:37 pm »

I modified the "Automatically resize image" mod posted earlier so that it also:
1.) Automatically creates a thumbmail of the image you are uploading
2.) Upon deleting the original image, also deletes the thumbnail
3.) Displays the thumbnail (if available) on the homepage, but the actual (full-size) image in the article.

If you are interested, I can post my changes.

What I am working on now is what you describe above... Posting an image for an article in real-time.
I am new to posting on the forum, but have been watching and playing with sNews and  haing a blast.
Logged

ketut

  • Full Member
  • ***
  • Karma: 0
  • Posts: 115
    • Book Bali Hotels
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #5 on: September 21, 2006, 02:07:08 am »

Quote from: Fotrane
I modified the "Automatically resize image" mod posted earlier so that it also:
1.) Automatically creates a thumbmail of the image you are uploading
2.) Upon deleting the original image, also deletes the thumbnail
3.) Displays the thumbnail (if available) on the homepage, but the actual (full-size) image in the article.
Hi! Fotrane, Yes I want to this mod like.
Please let us try your modul! Is it also work with snews ver 1.5?

Thanks

Fotrane

  • Newbie
  • *
  • Karma: 1
  • Posts: 28
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #6 on: September 21, 2006, 04:43:37 pm »

Edited 9-22-2006

My changes were quick and dirty, but seem to do the trick. Keep in mind, this is a "son of a mod", so I take little credit. Any referenced line numbers may differ from those in your file.

snews.php:
At line 74:
Code: [Select]
// Mods
$s['image_max_size'] = "340"; //specify resize width of uploaded images
$s['tn_max_size'] = "125"; //specify resize width of generated thumbnails
Near line 700:
Find:

Code: [Select]

<? echo $r['title']; ?>
Change to:
Code: [Select]
   
                   

                    <? echo $r['title']; ?>
                   

                   
                   

                    <? echo $r['title']; ?>
                   

                   
                    Find the images() function and change to:
Code: [Select]
// ********
// IMAGES
// ********

function images() {
    if (isset($_GET['image'])) {
        $file_to_delete = s('image_folder') ."/". $_GET['image'];
$thumbnail_to_delete = s('image_folder') ."/tn_". $_GET['image'];
unlink($thumbnail_to_delete);
        unlink($file_to_delete);
        echo "

". l('deleted_success') ."

". l('back') ."

";
    } else { ?>
   


   
   

       


:


       


       


   
    if(isset( $_POST['upload'] )) {
        if ($_FILES['imagefile']['type']){
            //$upload_dir = s('image_folder') ."/";
            //copy ($_FILES['imagefile']['tmp_name'], $upload_dir .$_FILES['imagefile']['name']) or die ("Could not copy");
            //echo "

" .l('operation_completed'). "

";
                        //insert by Stretsh
            $upload_dir = s('image_folder') ."/";
            $known_photo_types = array(
                                'image/pjpeg' => 'jpg',
                                'image/jpeg' => 'jpg',
                                'image/gif' => 'gif',
                                'image/bmp' => 'bmp',
                                'image/x-png' => 'png'
                            );
            $gd_function_suffix = array(
                                'image/pjpeg' => 'JPEG',
                                'image/jpeg' => 'JPEG',
                                'image/gif' => 'GIF',
                                'image/bmp' => 'WBMP',
                                'image/x-png' => 'PNG'
                            );
            if(!array_key_exists($_FILES['imagefile']['type'], $known_photo_types))
            {
                echo "File ".$_FILES['imagefile']['name']." is not a photo
";
            }
            else
            {
                $new_id = $_FILES['imagefile']['name'];
                $filetype = $_FILES['imagefile']['type'];
                $extention = $known_photo_types[$filetype];
                $filename = $new_id;
$thumbnail = "tn_".$new_id;

                copy($_FILES['imagefile']['tmp_name'], $upload_dir."/".$filename) or die ("Could not copy");

                $size = GetImageSize( $upload_dir."/".$filename );
                if (($size[0] > s('image_max_size')) || ($size[1] > s('image_max_size'))) {
                    if($size[0] > $size[1])
                    {
                        $pic_width = s('image_max_size');
                        $pic_height = (int)(s('image_max_size') * $size[1] / $size[0]);
    $tn_width = s('tn_max_size');
                        $tn_height = (int)(s('tn_max_size') * $size[1] / $size[0]);
                    }
                    else
                    {
                        $pic_width = (int)(s('image_max_size') * $size[0] / $size[1]);
                        $pic_height = s('image_max_size');
                        $tn_width = (int)(s('tn_max_size') * $size[0] / $size[1]);
                        $tn_height = s('tn_max_size');                    
}

                    $function_suffix = $gd_function_suffix[$filetype];
                    $function_to_read = "ImageCreateFrom".$function_suffix;
                    $function_to_write = "Image".$function_suffix;
                    $source_handle = $function_to_read ( $upload_dir."/".$filename );
                    if($source_handle)
                    {
                        $destination_handle = ImageCreateTrueColor ( $pic_width, $pic_height );
                        ImageCopyResampled( $destination_handle, $source_handle, 0, 0, 0, 0, $pic_width, $pic_height, $size[0], $size[1] );
$thumbnail_handle = ImageCreateTrueColor ( $tn_width, $tn_height );
ImageCopyResampled( $thumbnail_handle, $source_handle, 0, 0, 0, 0, $tn_width, $tn_height, $size[0], $size[1] );
                    }
                    $function_to_write( $destination_handle, $upload_dir."/".$filename );
$function_to_write( $thumbnail_handle, $upload_dir."/".$thumbnail );
                    ImageDestroy($destination_handle );
ImageDestroy($thumbnail_handle );
                } else {
if($size[0] > $size[1]) {
  $tn_width = s('tn_max_size');
                        $tn_height = (int)(s('tn_max_size') * $size[1] / $size[0]);

} else {
$tn_width = (int)(s('tn_max_size') * $size[0] / $size[1]);
                 $tn_height = s('tn_max_size');  

}
$function_suffix = $gd_function_suffix[$filetype];
                    $function_to_read = "ImageCreateFrom".$function_suffix;
                    $function_to_write = "Image".$function_suffix;

                    $source_handle = $function_to_read ( $upload_dir."/".$filename );
                   $thumbnail_handle = ImageCreateTrueColor ( $tn_width, $tn_height );
ImageCopyResampled( $thumbnail_handle, $source_handle, 0, 0, 0, 0, $tn_width, $tn_height, $size[0], $size[1] );
$function_to_write( $thumbnail_handle, $upload_dir."/".$thumbnail );
ImageDestroy($thumbnail_handle );
}
                echo "

" .l('operation_completed'). "

";
            }
            //end insert by Stretsh

            $kb_size = round(($_FILES['imagefile']['size'] / 1024), 1);
            echo "

".$_FILES['imagefile']['name']. "  [ " .$kb_size. " KB ] [ " .$_FILES['imagefile']['type']." ]";
        } else {
            echo "

" .l('admin_error'). "

";
            echo "

" .l('image_error'). "

";
        }
    } else {
        $upload_dir = s('image_folder') ."/";
        $handle= opendir($upload_dir);
        $filelist = "";
        while ($file = readdir($handle)) {
           if(!is_dir($file) && !is_link($file) && $file <> "Thumbs.db") {
            $filelist .= "".$file." [ Delete ]
";
    }}
    echo "

". l('saved_images') .":

";
    echo "

" .$filelist. "

";
}}}
And, no, I dont think this works with 1.5, I ahevn't even started playing with 1.5 yet.
Logged

Zucye

  • Sr. Member
  • ****
  • Karma: 5
  • Posts: 347
    • Simplemente una Mujer
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #7 on: September 21, 2006, 09:03:05 pm »

This sound interesting and useful I think I will try it later.
Logged
We can always learn from our failures, not so much from obvious success - C. Robinson (W. Disney). :)

ketut

  • Full Member
  • ***
  • Karma: 0
  • Posts: 115
    • Book Bali Hotels
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #8 on: September 22, 2006, 06:16:05 am »

Thanks for your good mod, work well for me!
but only thumbnail display on both list article and full article page.

how can I replace thumbnail image when we viewed the full article?

Fotrane

  • Newbie
  • *
  • Karma: 1
  • Posts: 28
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #9 on: September 22, 2006, 04:36:03 pm »

My mistake, I omitted some code. Try this in the article display section instead of what I have above:
Code: [Select]


<? echo $r['title']; ?>



<? echo $r['title']; ?>


Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #10 on: September 22, 2006, 05:11:12 pm »

Fotrane... Could you please edit your first post to contain this aswell, other wise when this thread grow longer, people will try the first piece of code without looking firther down in the thread in order to find the "last update", better of always editing the first post and also telling that in the post eg:

UPDATE 2006-09-22, or something like that ;)

Patric.
Logged
"It's only dead fish that goes with the flow... "
Updated

ketut

  • Full Member
  • ***
  • Karma: 0
  • Posts: 115
    • Book Bali Hotels
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #11 on: September 22, 2006, 06:00:51 pm »

OK! great -- thanks very much Mr. Fortrane
Now all work :)
blog.nusa-penida.com

ketut

  • Full Member
  • ***
  • Karma: 0
  • Posts: 115
    • Book Bali Hotels
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #12 on: October 16, 2006, 11:08:59 am »

Have someone use this great modul?
Please have a look at my site for demo http://blog.nusa-penida.com
Thanks

Lucian

  • Newbie
  • *
  • Karma: 0
  • Posts: 7
    • http://www.editiaspeciala.com
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #13 on: November 03, 2006, 02:30:46 pm »

Does somebody know if this is working in 1.5? :)
Logged

Fotrane

  • Newbie
  • *
  • Karma: 1
  • Posts: 28
[MOD] Automatically resize image 2 (sNews 1.4)
« Reply #14 on: November 03, 2006, 04:26:48 pm »

I re-coded it for snews 1.5 -- however, in order for it wto work in the same manner, it also requires some database structure changes, etc.

I am currently waiting for 1.5 Stable before posting thisw just to prevent any unexpected changes.
Logged
Pages: [1] 2