Jump to content

Auto Image Resize


Guest ViruzcK

Recommended Posts

It's a lot easier said than done. ;)

The only *reliable* way I've seen this work is with some nifty javascript (I've tested different methods on my old site with a mod Pit made for 1.3). Because images in [img ] tags are remote links, it's harder for a php script to reliably obtain the dimensions (that is, support varies across servers/php versions).

Link to comment
Share on other sites

It's a lot easier said than done. ;)



The only *reliable* way I've seen this work is with some nifty javascript (I've tested different methods on my old site with a mod Pit made for 1.3). Because images in [img ] tags are remote links, it's harder for a php script to reliably obtain the dimensions (that is, support varies across servers/php versions).




this image resize that I did, is in javascript and works with Internet iexplorer and mozilla, is sure since with php they can take place times out

IPB version 2.1.6

(if image width > 50% of width screen Adjust width to 50% of screen)

sources/classes/bbcode/class_bbcode.php sources/classes/bbcode/class_bbcode_core.php sources/classes/bbcode/class_bbcode_legacy.php sources/lib/post_parser.php /*in file: sources/classes/bbcode/class_bbcode.php*/ in function pre_edit_parse FIND: $txt = preg_replace( "#<img src=[\"'](\S+?)['\"].+?".">#" , "\[img\]\\1\[/img\]" , $txt ); REPLACE with: //Resize Img //$txt = preg_replace( "#<img src=[\"'](\S+?)['\"].+?".">#" , "\[img\]\\1\[/img\]" , $txt ); $txt = preg_replace( "#<!--UserPostedImage-->\n<img src=[\"'](\S+?)['\"].+?"." /><!--UserPostedImage-->#" , "\[img\]\\1\[/img\]" , $txt ); $txt = preg_replace( "#<img src=[\"'](\S+?)['\"].+?".">#" , "\[img\]\\1\[/img\]" , $txt ); //Resize Img /*in file: sources/classes/bbcode/class_bbcode_legacy.php*/ in function pre_edit_parse FIND: $txt = preg_replace( "#<img src=[\"'](\S+?)['\"].+?".">#" , "\[img\]\\1\[/img\]" , $txt ); REPLACE with: //Resize Img //$txt = preg_replace( "#<img src=[\"'](\S+?)['\"].+?".">#" , "\[img\]\\1\[/img\]" , $txt ); $txt = preg_replace( "#<!--UserPostedImage-->\n<img src=[\"'](\S+?)['\"].+?"." /><!--UserPostedImage-->#" , "\[img\]\\1\[/img\]" , $txt ); $txt = preg_replace( "#<img src=[\"'](\S+?)['\"].+?".">#" , "\[img\]\\1\[/img\]" , $txt ); //Resize Img /*in file: sources/lib/post_parser.php*/ in function unconvert FIND: $txt = preg_replace( "#<img src=[\"'](\S+?)['\"].+?".">#" , "\[img\]\\1\[/img\]" , $txt ); REPLACE with: //Resize Img //$txt = preg_replace( "#<img src=[\"'](\S+?)['\"].+?".">#" , "\[img\]\\1\[/img\]" , $txt ); $txt = preg_replace( "#<!--UserPostedImage-->\n<img src=[\"'](\S+?)['\"].+?"." /><!--UserPostedImage-->#" , "\[img\]\\1\[/img\]" , $txt ); $txt = preg_replace( "#<img src=[\"'](\S+?)['\"].+?".">#" , "\[img\]\\1\[/img\]" , $txt ); //Resize Img /*in file: sources/classes/bbcode/class_bbcode_core.php*/ in function regex_check_image() REPLACE : return "<img src=\"$url\" border=\"0\" alt=\"{$this->ipsclass->lang['bbcode_img_alt']}\" />"; REPLACE with: //Resize Img //return "<img src=\"$url\" border=\"0\" alt=\"{$this->ipsclass->lang['bbcode_img_alt']}\" />"; return "<!--UserPostedImage--><br /><img src=\"$url\" title=\"{$this->ipsclass->lang['bbcode_img_alt']}\" border=\"0\" onload=\"if(this.width>screen.width*0.5) {this.resized=true; this.width=screen.width*0.5; this.title='Pincha Aqui para ver esta imagen en su tama
- Files to edit



































































Link to comment
Share on other sites

can you write one for 2.0.x ? thx.



For 2.0.x only apply changes of the files:

sources/lib/post_parser.php

changes in file :
sources/classes/bbcode/class_bbcode_core.php --> apply in:
sources/lib/post_parser.php
very easy

'Pincha Aqui para ver esta imagen en su tama
Link to comment
Share on other sites

We don't want all that js inline in the post.



That said, I've figured out a "cleaner" way to do this, working in IE, Opera and Firefox.


It will create a new code that works with a function js, it seems to you?, but there exists the possibility of including it in the new version of ipb?
Link to comment
Share on other sites

Hmmmmm... I hope there is a way to turn off the auto size thing. I dont want images to be auto sized at all.

Rather I would rather have the option to do this:

[ img width="100" height="100"]

Or something like that.

Link to comment
Share on other sites

  • Management

Does the vB feature only resize attached images though? That's what I gleaned from the feature. I don't think it resizes images posted via tags.

Ours will use JS to reduce the dimensions of the . We've been resizing uploaded images since IPB 2.0.0.

Link to comment
Share on other sites

Sure...if the image is [b]uploaded[/b].



This resizes attached images as well as uploaded images.


Naw, as long as PHP allows fopen URL wrappers, it could easily be done :) (with PHP 4.0.5 and above)
Link to comment
Share on other sites

Naw, as long as PHP allows fopen URL wrappers, it could easily be done :) (with PHP 4.0.5 and above)



But when it is not possible to open the url or is late very much, php returns time out error it was, for this it is not suitable

js is solution


PD :In js the work it does the computer of the visitor, but in php the work realizes the Server
Link to comment
Share on other sites

We've been resizing uploaded images since IPB 2.0.0.



Matt,

It's interesting that you say this because I was going to make a feature request dealing with this issue. I'm sorry if I'm missing something as I'm new to administering IPB.

I have IPB and also the Gallery and Blog. I've noticed that with the Gallery if a member tries to upload a large image, say 2MB, it returns a non-descript error. My members (artists) have no idea why this happened because it doesn't really say "Your image is too large, please resize it before uploading" or something like that. It just breaks non-gracefully (Yeah, I just made up that word :whistle: ).

On the other end of the spectrum, in the forums my users can upload any size of image (up to the post size limit of course) in a posting. I had one person uploading 1.5MB images that came straight from her digital camera. Not only did they take up a lot of space, but when you clicked on the little icon it took you to the full size version.

Now, I don't want to remove my users ability to post 1.5MB files, because they might put up a PowerPoint or PDF or something useful. But I also don't want 1.5MB images because with 200 artists doing this they'll bring my server to it's knees.

So my question is, could IPB be made to do something like the following:
  • All image attachments over an admin selected size (either resolution or filesize) would be automatically resized (in every module, Gallery, Board, Blog). The large original should be discarded. This allows non-techie users to upload whatever they have and the system does the work.
  • Attachment size limits would be selectable by extension. For example: .pdf=1MB; .ppt=2MB; .zip/.rar=3MB; .avk/.mov/.wmv=4mb. If it ain't listed, it has a default of 0kb - or can't upload!
  • If a user attempts an oversized upload the system tells them exactly why: "Sorry, but the attachment size limit for PDFs is 1MB" or "This filetype is not allowed"
Again, sorry if I'm already missing something the system can do and I just don't know it yet, but these would be extremely useful to my community.

Cheers,

John
Link to comment
Share on other sites

Archived

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...