Gitlab trick: Automatically resize uploaded images

2 min.

Some little tricks are simply too good not to share. Here is one of them.

Images attached to an issue in Gitlab are always displayed full-width, which makes especially screenshots and others assets very space consuming.

To improve this you can replace the image reference with html to specify the desired display of the image. Below is an example.

Automatic markup after upload:

![Filename](/uploads/7ed860277251c934b53c95c3242ff8ea/Filename.jpg)

Manually changed markup:

<img src="/uploads/7ed860277251c934b53c95c3242ff8ea/Filename.jpg" width=320 />

GitLab Resize Images Display
Screenshot of issue in Gitlab with two images, one is resized, the other on is not resized.

However, when you often upload images, this a repetitive task.

Luckily, my colleague Rouven Volk came up with a nice little JS.

With a very simple bookmark you can automatically resize the images.  Create the bookmark and insert the following snippet to the URL:

javascript: (function(e, w) {
    e.value = e.value.replace(/\!\[[^\]]+\]\(([^\)]+)\)/g, "<img src=\"$1\" width=" + w + " />");
})(document.querySelector('textarea.markdown-area'), 320)

 

This is what the bookmark looks like in Chrome browser:

Bookmark view

 

Bookmark with JS in the URL.

When you edit an issue or comment in Gitlab and click the bookmark, the markup of uploaded images automatically get replaced.

Resized image view

Other highlights

Knowledge base

New Analytics Tool: Google Analytics 4

1x_website_mood_career_2021

In November last year, Google announced its newest project: Google Analytics 4 ( hereafter called...

5 min.
Knowledge base

GDPR Cookie Consent Banner

Consent Banner

What is a Cookie Consent banner and what is the difference to the previous cookie notification. In...

4 min.