In this tutorial, I will show how you can create an image BBCode with customizable image dimensions for the forum software
phpBB like I did
here. The embedded image will be responsive and open in a lightbox if the
Lightbox extension is installed and activated.
Go to your Administration Control Panel (ACP) and navigate to the POSTING tab. There you can see a list of (custom) BBCodes (it can be empty though). Click on the "Add new BBCode" button.
Under "
BBCode usage" paste the following into the field:
This is the BBCode itself which can later used in posts when the HTML replacement is set up correctly. The {NUMBER} token is a placeholder for the max width of pixels the embedded image can have. The {URL} token stands for the direct link of the image. The c in "imgc" stands for custom image dimension but you can choose another name for your custom image BBCode (just keep in mind to adjust the first and third code snippet accordingly).
In the field under "
HTML replacement" comes this code snippet:
Code: Select all
<img src="{URL}" style="max-width: {NUMBER}px!important; max-height: unset!important; width: 100%!important; height: 100%!important" class="postimage"/>
It's important that the tokens from the first field appear in the second field as well, otherwise you will get an error message when you try to save the BBCode.
The
<img> tag lets you insert the image in the post. The look of the image is controlled with the
style attribute. I used the
max-width property to adjust the max width of the inserted image and set the
width and
height properties to 100% each to make the inserted image responsive. The
!important rule makes sure that the previous styling rules for the element in question are overridden. Assigning the "postimage" class to the BBCode enables the lightbox from the Lightbox extension for the inserted image and the image opens in a lightbox when clicked on by the user.
Edit: I edited the code to unset the maximum height so that embedded images are displayed with the specified width, provided the browser window is large enough (my tests with the inspection tools show that the browser window needs to have a width that is greater than 1289 pixels)
In the third field (under "
Help line"), you can write some helpful text for the user to show him or her how to use the BBCode. The text appears when the user hovers with the mouse over the BBCode in the posting buttons bar in the posting editor.
Example help line text:
Code: Select all
[imgc=number]image URL[/imgc]
embeds an image with a custom max width
sample 1000px max width:
[imgc=1000]https://staticdelivery.nexusmods.com/images/1151/287627-1612995239.jpg[/imgc]
Last but not least you can determine, if your new BBCode should be displayed in the posting editor by activating the small box next to "
Display on posting page".
Image of the settings in the ACP:
Click on "Submit" to save your BBCode.
I took the sample from the sample help line text to show you how the final BBCode can look in posts:
Code: Select all
[imgc=1000]https://staticdelivery.nexusmods.com/images/1151/287627-1612995239.jpg[/imgc]
(the figure in the picture is my Fallout 4 character btw
)
In this tutorial, I will show how you can create an image BBCode with customizable image dimensions for the forum software [url=https://www.phpbb.com]phpBB[/url] like I did [url=https://modding-on-the-spectrum.com/viewtopic.php?f=8&t=65]here[/url]. The embedded image will be responsive and open in a lightbox if the [url=https://www.phpbb.com/customise/db/extension/lightbox/]Lightbox[/url] extension is installed and activated.
Go to your Administration Control Panel (ACP) and navigate to the POSTING tab. There you can see a list of (custom) BBCodes (it can be empty though). Click on the "Add new BBCode" button.
Under "[b][color=#BFFFFF]BBCode usage[/color][/b]" paste the following into the field:
[code][imgc={NUMBER}]{URL}[/imgc][/code]
This is the BBCode itself which can later used in posts when the HTML replacement is set up correctly. The {NUMBER} token is a placeholder for the max width of pixels the embedded image can have. The {URL} token stands for the direct link of the image. The c in "imgc" stands for custom image dimension but you can choose another name for your custom image BBCode (just keep in mind to adjust the first and third code snippet accordingly).
In the field under "[b][color=#BFFFFF][anchor]HTML replacement[/anchor][/color][/b]" comes this code snippet:
[code]<img src="{URL}" style="max-width: {NUMBER}px!important; max-height: unset!important; width: 100%!important; height: 100%!important" class="postimage"/>[/code]
[color=#FFFF00]It's important that the tokens from the first field appear in the second field as well, otherwise you will get an error message when you try to save the BBCode.[/color]
The [url=https://www.w3schools.com/tags/tag_img.asp]<img> tag[/url] lets you insert the image in the post. The look of the image is controlled with the [url=https://www.w3schools.com/tags/att_style.asp]style[/url] attribute. I used the [url=https://www.w3schools.com/cssref/pr_dim_max-width.php]max-width[/url] property to adjust the max width of the inserted image and set the [url=https://www.w3schools.com/cssref/pr_dim_width.php]width[/url] and [url=https://www.w3schools.com/cssref/pr_dim_height.php]height[/url] properties to 100% each to make the inserted image responsive. The [url=https://www.w3schools.com/css/css_important.asp]!important[/url] rule makes sure that the previous styling rules for the element in question are overridden. Assigning the "postimage" class to the BBCode enables the lightbox from the Lightbox extension for the inserted image and the image opens in a lightbox when clicked on by the user.
[b][color=#FFFF00]Edit:[/color][/b] I edited the code to unset the maximum height so that embedded images are displayed with the specified width, provided the browser window is large enough (my tests with the inspection tools show that the browser window needs to have a width that is greater than 1289 pixels)
In the third field (under "[b][color=#BFFFFF]Help line[/color][/b]"), you can write some helpful text for the user to show him or her how to use the BBCode. The text appears when the user hovers with the mouse over the BBCode in the posting buttons bar in the posting editor.
Example help line text:
[code][imgc=number]image URL[/imgc]
embeds an image with a custom max width
sample 1000px max width:
[imgc=1000]https://staticdelivery.nexusmods.com/images/1151/287627-1612995239.jpg[/imgc][/code]
Last but not least you can determine, if your new BBCode should be displayed in the posting editor by activating the small box next to "[b][color=#BFFFFF]Display on posting page[/color][/b]".
[i]Image of the settings in the ACP:[/i]
[attachment=0]MotS_custom_img_BBCode_tutorial.jpg[/attachment]
Click on "Submit" to save your BBCode.
I took the sample from the sample help line text to show you how the final BBCode can look in posts:
[code][imgc=1000]https://staticdelivery.nexusmods.com/images/1151/287627-1612995239.jpg[/imgc][/code]
[imgc=1000]https://staticdelivery.nexusmods.com/images/1151/287627-1612995239.jpg[/imgc]
(the figure in the picture is my Fallout 4 character btw ;))