Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: ApplianceJunk on April 14, 2014, 09:12:00 PM

Title: Resize Attached Images Mods for SMF 2.0.x?
Post by: ApplianceJunk on April 14, 2014, 09:12:00 PM
Looking for mods that auto resize attached images.
The only one I can seem to find is this one.

http://custom.simplemachines.org/mods/index.php?mod=2206

Thinking there was another one when I looked some time ago. I'm I missing something?

Thanks,
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: margarett on April 14, 2014, 09:29:26 PM
To resize the attached images is the only one I found.
There are some others to resize the images displayed, but the real attachment, not that I know of...
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: ApplianceJunk on April 14, 2014, 09:31:20 PM
Hmm, did some mod makers move there mods from SMF to their own sites?
Maybe it was on another site I seen it?
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: mashby on April 14, 2014, 09:37:33 PM
I thought SMF did this on its own (well, by settings in Features and Options > Layout).
Max width of posted pictures (0 = disable)
Max height of posted pictures (0 = disable)
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: ApplianceJunk on April 14, 2014, 09:40:20 PM
Was thinking I seen a mod that resized the file size not just the dimension so you could save space on your server.
A lot of my members can't seem to figure out how to resize a photo themselves before uploading it.
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: margarett on April 14, 2014, 09:41:30 PM
@AJ, I can see even removed MODs but, if the user scrambled the name when removing it, then it can't be found by "resize" anymore. So I can't really tell...

@mashby: that resizes the *displayed* image. The MOD AJ mentions resizes the attachment itself.
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: mashby on April 14, 2014, 09:45:17 PM
OK, on another site I help with, the attached images thumbnails settings are what I'm seeing. What's wrong with the mod you linked to AJ? Seems to do what you might be wanting. :)
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: ApplianceJunk on April 14, 2014, 09:48:53 PM
Quote from: mashby on April 14, 2014, 09:45:17 PM
OK, on another site I help with, the attached images thumbnails settings are what I'm seeing. What's wrong with the mod you linked to AJ? Seems to do what you might be wanting. :)

It talks about resizing dimension and nothing about changing the file size.

Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: mashby on April 14, 2014, 09:50:35 PM
Maybe not explicitly, but if you take a large dimension image and resize it to a smaller dimension and then save it, you will hopefully get a smaller file size as a result. If you don't, I'd be shocked/amazed/disappointed.
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: ApplianceJunk on April 14, 2014, 10:05:08 PM
Ok, I'm thinking along these lines as to how the displayed photo dimension size can be changed without changing the file size.
http://www.bbcode.org/examples/?id=10

Not sure if that is all the mod I posted is doing, just changing the size that is being displayed or actually changing the file size.
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: mashby on April 14, 2014, 10:07:19 PM
I'm not entirely familiar with the mod, but it sure seems like it does what you need. The link you just provide is merely using HTML to resize the image, the entire time, all of the images being referenced is this:
http://www.bbcode.org/images/lubeck_small.jpg
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: margarett on April 14, 2014, 10:10:26 PM
It is changing BOTH because it really changes the image itself.

If you attach a big picture, taken with a state-of-the-art 200 megapixels camera which, in JPG format, takes 100Mb ;D This MOD would send to your server's filesystem a much smaller, eg 1024x768px with 400kB (or whatever filesize it becomes after resizing)
If you don't use this, you will end up with an attached file of 100Mb that would need to be fully loaded. That image would have like... 12231231232 x 5533233 px ;D
SMF (with that BBC you linked) would resize it like mashby points *BUT* after it had been fully loaded.

See the difference? ;)
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: Kays on April 15, 2014, 08:48:58 AM
The physical file size is determined by the dimensions. Width x height x 3 (colours) is the size as a bit map image. Or what you'd see if you were looking at it in a photo editor. Then when it is saved as a jpeg image, the physical size is reduced.
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: a10 on April 15, 2014, 09:50:46 AM
QuoteA lot of my members can't seem to figure out how to resize a photo themselves before uploading it
One meets those trying to upload some 5 x 4 Meter pictures, with zero understanding (what's the problem? looks small on my camera\pc\phone display).

I set file types and max file size, and stick to it whatever happens, providing much info in the faq, with links to programs for resizing and a help section. Extra work, but 99% gets the how's & why's without too much whining. Those few who can't grasp it I refer to use some image hosting, or get them to ask for help from family or friends. Of course, some easy to use built-in auto-resize could be nice.
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: szinski on October 20, 2014, 09:50:58 AM
I love the "Resize Attached Images" mod (thanks Kays)... it allows iPhone users to upload images to my forum without having to resize them first. But, I'm having an issue with image orientation. A lot of iPhone images have the wrong orientation... sideways, upsidedown, etc... Does anyone know of a mod that will automatically read the exif data on an image and set the correct orientation during image upload?
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: margarett on October 20, 2014, 09:53:04 AM
This has been discussed in another topic not long ago.

In short: it's quite technical and difficult, there are currently no mods to fix that...
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: Westwegoman on October 20, 2014, 10:26:53 AM
Quote from: ApplianceJunk on April 14, 2014, 09:40:20 PM
Was thinking I seen a mod that resized the file size not just the dimension so you could save space on your server.
A lot of my members can't seem to figure out how to resize a photo themselves before uploading it.

AJ, the mod you mentioned in your first post would do this. I use it on my forum and it works great. Saves a lot of space and most of all, your members won't have to worry about resizing themselves.
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: roshaoar on April 28, 2015, 06:01:03 PM
Quote from: margarett on October 20, 2014, 09:53:04 AM
This has been discussed in another topic not long ago.

In short: it's quite technical and difficult, there are currently no mods to fix that...

Hello Margarett, can you point me to a link for this discussion? Thanks
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: margarett on April 28, 2015, 06:33:15 PM
IIRC, Arantor's gallery features that automatic rotation (which he implemented).
It's paid stuff, though.

I'll try to find the discussion ;)

edit: I think it's this
http://www.simplemachines.org/community/index.php?topic=514372.msg3636111#msg3636111
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: roshaoar on April 29, 2015, 02:31:10 AM
Thanks Margarett
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: roshaoar on April 29, 2015, 02:07:18 PM
Quote from: Blue Crab on October 20, 2014, 09:50:58 AM
I love the "Resize Attached Images" mod (thanks Kays)... it allows iPhone users to upload images to my forum without having to resize them first. But, I'm having an issue with image orientation. A lot of iPhone images have the wrong orientation... sideways, upsidedown, etc... Does anyone know of a mod that will automatically read the exif data on an image and set the correct orientation during image upload?

Just wanted to mention a bodge that'll help, at least for images in posts using the IMG BBC tag. The mod I just found "BBCode with style" (http://custom.simplemachines.org/mods/index.php?mod=2505) allows CSS rotation to be added to an image. With rotation it's really easy for the poster to set their image right. It works in my testexample really well - http://goo.gl/iWtQjS - the 4th and 5th and 6th posts are the same image. 5 uses user-set (ie the poster does it) styles to get it pointing the right way.
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: szinski on February 25, 2016, 03:18:31 PM
I am reporting back to say that I have found a solution to the exif orientation problem.

Using the Resize Attached Images mod, add the following code above/before the line that reads "// Added for the Image resize mod" in Sources/Post.php.

NOTE: In order for this to work, your PHP server must be built with the --enable-exif configuration option, and the Re-encode potentially dangerous image attachments option turned off under attachment settings in SMF.



            $imageFile = $dummy;
            $imageSize = getimagesize($imageFile);
           
            if ($imageSize['mime'] == 'image/jpeg') {
                $imageExif = exif_read_data($imageFile);
                $imageOrientation = $imageExif['Orientation'];

                if ($imageOrientation) {
                    $image = imagecreatefromjpeg($imageFile);
                    $imageRotated = false;

                    switch($imageOrientation) {
                        case 3:
                            $image = imagerotate($image, 180, 0);
                            $imageRotated = true;
                            break;
                        case 6:
                            $image = imagerotate($image, -90, 0);
                            $imageRotated = true;
                            break;
                        case 8:
                            $image = imagerotate($image, 90, 0);
                            $imageRotated = true;
                            break;
                    }

                    if ($imageRotated) {
                        imagejpeg($image, $imageFile);
                    }

                    imagedestroy($image);
                }
            }



I have this running on my forum and now people can upload photos straight from their iPads/iPhones and the orientation is correct. A big shout-out to member "dsissitka" on my forum for finding this solution.
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: FrizzleFried on March 15, 2016, 11:53:42 AM
I can CONFIRM the code above works FANTASTICALLY!

Awesome!

Thanks!
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: szinski on March 15, 2016, 01:50:07 PM
While the above code works, I found that it generates an error if the image doesn't contain orientation information (it's a harmless error and can be ignored). But, no code should generate errors, so here is version 2.0 which checks to see if the 'Orientation' key exists before trying to rotate it.


                        // Rotate image according to Exif orientation
                        $imageFile = $dummy;
                        $imageSize = getimagesize($imageFile);

                        if ($imageSize['mime'] == 'image/jpeg')
                        {
                                $imageExif = exif_read_data($imageFile);

                                if (array_key_exists('Orientation', $imageExif))
                                {
                                        $imageOrientation = $imageExif['Orientation'];
                                        $image = imagecreatefromjpeg($imageFile);
                                        $imageRotated = false;

                                        switch($imageOrientation)
                                        {
                                                case 3:
                                                        $image = imagerotate($image, 180, 0);
                                                        $imageRotated = true;
                                                        break;
                                                case 6:
                                                        $image = imagerotate($image, -90, 0);
                                                        $imageRotated = true;
                                                        break;
                                                case 8:
                                                        $image = imagerotate($image, 90, 0);
                                                        $imageRotated = true;
                                                        break;
                                        }

                                        if ($imageRotated)
                                                imagejpeg($image, $imageFile);

                                        imagedestroy($image);
                                }
                        }


Enjoy!
Title: Re: Resize Attached Images Mods for SMF 2.0.x?
Post by: jakes_t on December 27, 2016, 09:27:44 AM
Just a heads up to anybody also facing the same problem, the resize mod together with this above code works nicely to keep file sizes nice and small as well as correctly orientating the image.

Users can now upload pics directly from their phones and have it orientated correctly and reduced in size.