• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Headless Support Patch

 
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who's this for?

If you're getting this error message when attaching images:

Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.



And the following flag isn't solving the problem:

-Djava.awt.headless=true



Then you need this patch.

What causes the problem?

The problem is caused by a lack of X11 libraries on your server system. The AWT subsystem that resizes images can do so in a headless environment, but only if X11 is installed. If the libraries don't exist, then the AWT commands will fail.

The normal solution is to install the X Libraries. This works when you control your server, but fails when you don't. This patch will allow you to use headless image resizing even if you don't have the X11 libraries on your system.

How do I use it?

1. Replace the ImageUtils.java file in the src/net/jforum/util/image directory with the attached file.

2. Recompile your copy of JForum and deploy*.

3. Modify your jforum-custom.conf file. Add the following line:

4. You should now be able to allow image attachments with thumbnails turned on.

* Note that you should make a backup of your jforum-custom.conf file and uploads folder before deploying a new version, as these files will be wiped out by the redeploy. You can restore them from your backup after you have finished deploying the new version.

What won't this patch do?

This patch only addresses image support for attachments. Issues with the Captcha code are not addressed by this patch. You may need to disable the captchas, or look into the solution provided in JCaptcha's FAQ.
[originally posted on jforum.net by jbanes]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a thought, but you may wish to consider using the Bilinear resizing of this patch as the standard image resizing method. I ran across a few of the images in the Test forum, and decided to do a bit of comparison. The first one that stuck out at me was the Guinness image:


(Standard on the left, Bilinear on the right)

That was quite a difference, so I decided to do a few more:









In all cases, the Bilinear image came out as good as, or better than the image resized by the current forum software. From the graphics above, it seems that photographic images show less of a difference than non-photographic images. A difference still exists (e.g. look at the striped shirt in the upper-right corner of the last photo; as well as the hat line of the upper-left shot in the last image), but it's far less noticable.

The advantages of using Bilinear resizing are:

1. The forum software will no longer depend on the AWT subsystem for image handling.

2. The output will look better.

3. No need to worry about headless systems.


The disadvantages come down to pretty much one issue:

1. Bilinear resizing is usually slower, possibly taking a second or two of CPU time to resize the image.

Since the resize is a one-time cost, it shouldn't make a major impact on the site unless the forum is dealing with a constant stream of image uploads.

Like I said, it's just a thought. I'd be happy to answer any questions you have. Thanks!
[originally posted on jforum.net by jbanes]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, you suggest to remove createBufferedImage() and always use createHeadlessSmoothBufferedImage() ?

I added your code to the cvs.. thanks A LOT

Rafael
[originally posted on jforum.net by Rafael Steil]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So, you suggest to remove createBufferedImage() and always use createHeadlessSmoothBufferedImage() ?


Yep, that's my suggestion. If you go with the Bilinear scaling as the standard, you don't need the headless flag at all.

I added your code to the cvs.. thanks A LOT


Glad to help. I'll post more patches as I fix stuff for my installation.
[originally posted on jforum.net by jbanes]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Done!

Any ideas on how to handle gifs? Currently, gifs are saved as png, which is a problem for animated images.

Rafael
[originally posted on jforum.net by Rafael Steil]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there are quite a few free libraries that will encode animated GIFs. The only question in my mind is: Why are they being reencoded in the first place? Presumably, avatars should be used as-is if they meet the size/dimension standards. Reencoding them is just as likely to make them bigger, not smaller. So the best solution there is to bypass reencoding.

As for thumbnails, I presume you don't want those animated anyway, do you? Or is that a feature that the user should be able to control? If so, then it would be pretty easy to plug in one of the libraries above depending on the user setting. Resizing might be a bit tricky to write, though. I'd need to look at how the image data is encoded before I could give you a firm answer on how that would work.

BTW, any GIF resizing you do (that's not saved as a PNG, that is) cannot use the Bilinear filter. There isn't enough colors in a GIF image to allow blending like that. I left a Nearest Neighbor scaler in the code, so that shouldn't be a problem. However, the images won't scale quite as nicely.
[originally posted on jforum.net by jbanes]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a certain ammount of complain about JForum not supporting animated gifs for the avatars, that's all.

Those libraries would in fact help, or do you want to try something else first?

Rafael
[originally posted on jforum.net by Rafael Steil]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess what I'm saying is, that the forum should reject uploads larger than the max size rather than trying to resize them. When you resize them, any sort of fil-size limitation becomes meaningless. What might have been a 5K upload may accidently turn into a 20K upload upon recompression. As a result, it's best to use the source image whenever possible.

This little patch does that trick. If the source image is less than or equal to the max size, it's used as-is. If it's larger, it will resize it as a smaller JPG or PNG. I tested it with a few avatars (including the Gator fellow) and it works just fine. The only downside is that the animation will be lost if it's larger than the forum maximum size. If you fix the sentence ("This image cannot be larger than 130x130 pixels.") to reflect the actual forum size, then it's probably fine as-is.


[originally posted on jforum.net by jbanes]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!