Skip to content

Commit aec92a2

Browse files
authored
Merge pull request #6 from memeller/bmp_support
bmp support
2 parents 4bb3bc8 + 313aaa8 commit aec92a2

File tree

8 files changed

+62
-15
lines changed

8 files changed

+62
-15
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Changelog
1+
# Changelog
2+
3+
## v5.5
4+
5+
- Added BMP support (inline and as attachment) - bmp files are converted to jpeg when resizing.
26

37
## v5.4
48

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ Since the original repo is no longer mantained and became read-only on 28th of D
55

66
## About this extension
77

8-
After installing each time a compatible (JPG/PNG) image is attached to/inserted into new e-mail the user has the ability to resize the image. The resized image replaces previously inserted / attached one.
8+
Each time a compatible (JPG/PNG/BMP) image is attached to/inserted into new e-mail the user has the ability to resize the image. The resized image replaces previously inserted / attached one.
99

1010
## New in this fork (vs darkrojan's version):
1111

1212
- Added PL lang support,
13+
- BMP support (converted to JPG when resized),
1314
- PNG support,
1415
- "Automatically rotate images" can now be checked - there was an issue with parameter name which caused the option to be permanently disabled,
1516
- Resampling finally works

api/shrunked.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ var shrunked = class extends ExtensionCommon.ExtensionAPI {
105105
reader.onloadend = function () {
106106
let dataURL = reader.result;
107107
let headerIndexEnd = dataURL.indexOf(";");
108-
dataURL = reader.result.substring(0, headerIndexEnd) + ";filename=" + encodeURIComponent(destFile.name) + dataURL.substring(headerIndexEnd);
108+
dataURL = reader.result.substring(0, headerIndexEnd) + ";filename=" + encodeURIComponent(changeExtensionIfNeeded(destFile.name)) + dataURL.substring(headerIndexEnd);
109109
resolve(dataURL);
110110
};
111111
reader.readAsDataURL(destFile);
@@ -145,7 +145,7 @@ var shrunked = class extends ExtensionCommon.ExtensionAPI {
145145

146146
if (!indicies.length) {
147147
if (logenabled)
148-
console.log("Not resizing - no attachments were JPEG/PNG and large enough");
148+
console.log("Not resizing - no attachments were JPEG/PNG/BMP and large enough");
149149
attachmentMenuItem.label = localeData.localizeMessage("context.unsupportedFile");
150150
} else if (indicies.length == 1) {
151151
attachmentMenuItem.label = localeData.localizeMessage("context.single");
@@ -367,10 +367,20 @@ var shrunked = class extends ExtensionCommon.ExtensionAPI {
367367
}
368368
}
369369
};
370+
function changeExtensionIfNeeded(filename) {
371+
let src = filename.toLowerCase();
372+
//if it is a bmp we will save it as jpeg
373+
if (src.startsWith("data:image/bmp") || src.endsWith(".bmp")) {
374+
return src.replace("bmp", "jpg");
375+
}
376+
else
377+
return src;
370378

379+
}
371380
function imageIsAccepted(url) {
372381
let src = url.toLowerCase();
373382
let isJPEG = src.startsWith("data:image/jpeg") || src.endsWith(".jpg") || src.endsWith(".jpeg");
374383
let isPNG = src.startsWith("data:image/png") || src.endsWith(".png");
375-
return isJPEG | isPNG;
384+
let isBMP = src.startsWith("data:image/bmp") || src.endsWith(".bmp");
385+
return isJPEG | isPNG | isBMP;
376386
}

background.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var tabMap = new Map();
22

33
async function shouldResize(attachment, checkSize = true) {
4-
if (!attachment.name.toLowerCase().match(/((\.jpe?g)|(\.png))$/)) {
4+
if (!attachment.name.toLowerCase().match(/((\.jpe?g)|(\.png)|(\.bmp))$/)) {
55
return false;
66
}
77
if (!checkSize) {
@@ -68,6 +68,7 @@ browser.compose.onAttachmentAdded.addListener(async (tab, attachment) => {
6868
}
6969
await browser.compose.updateAttachment(tab.id, attachment.id, {
7070
file: destFile,
71+
name: changeExtensionIfNeeded(destFile.name)
7172
});
7273
});
7374

@@ -96,7 +97,7 @@ browser.shrunked.onAttachmentContextClicked.addListener(async (tab, indicies) =>
9697
if (destFile === null) {
9798
return;
9899
}
99-
browser.compose.updateAttachment(tab.id, a.id, { file: destFile });
100+
browser.compose.updateAttachment(tab.id, a.id, { file: destFile, name: changeExtensionIfNeeded(destFile.name) });
100101
});
101102
}
102103
}
@@ -124,7 +125,7 @@ browser.compose.onBeforeSend.addListener(async (tab, details) => {
124125
if (destFile === null) {
125126
return;
126127
}
127-
await browser.compose.updateAttachment(tab.id, a.id, { file: destFile });
128+
await browser.compose.updateAttachment(tab.id, a.id, { file: destFile, name: changeExtensionIfNeeded(destFile.name) });
128129
});
129130
promises.push(promise);
130131
}
@@ -252,3 +253,13 @@ function cancelResize(tabId) {
252253
browser.tabs.onRemoved.addListener(tabId => {
253254
tabMap.delete(tabId);
254255
});
256+
function changeExtensionIfNeeded(filename) {
257+
let src = filename.toLowerCase();
258+
//if it is a bmp we will save it as jpeg
259+
if (src.startsWith("data:image/bmp") || src.endsWith(".bmp")) {
260+
return src.replace("bmp", "jpg");
261+
}
262+
else
263+
return src;
264+
265+
}

compose_script.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async function maybeResizeInline(target) {
7575
}
7676
if (!imageIsAccepted(target)) {
7777
if (logenabled)
78-
console.log("Not resizing - image is not JPEG / PNG");
78+
console.log("Not resizing - image is not JPEG / PNG / BMP");
7979
return;
8080
}
8181
if (target.width < 500 && target.height < 500) {
@@ -126,7 +126,7 @@ async function maybeResizeInline(target) {
126126
let dataURL = reader.result;
127127
let headerIndexEnd = dataURL.indexOf(";");
128128
dataURL =
129-
reader.result.substring(0, headerIndexEnd) + ";filename=" + encodeURIComponent(destFile.name) + dataURL.substring(headerIndexEnd);
129+
reader.result.substring(0, headerIndexEnd) + ";filename=" + encodeURIComponent(changeExtensionIfNeeded(destFile.name)) + dataURL.substring(headerIndexEnd);
130130
resolve(dataURL);
131131
};
132132
reader.readAsDataURL(destFile);
@@ -147,10 +147,21 @@ async function maybeResizeInline(target) {
147147
}
148148
}
149149
}
150-
150+
function changeExtensionIfNeeded(filename){
151+
let src=filename.toLowerCase();
152+
//if it is a bmp we will save it as jpeg
153+
if (src.startsWith("data:image/bmp") || src.endsWith(".bmp"))
154+
{
155+
return src.replace("bmp","jpg");
156+
}
157+
else
158+
return src;
159+
160+
}
151161
function imageIsAccepted(image) {
152162
let src = image.src.toLowerCase();
153163
let isJPEG = src.startsWith("data:image/jpeg") || src.endsWith(".jpg") || src.endsWith(".jpeg");
154164
let isPNG = src.startsWith("data:image/png") || src.endsWith(".png");
155-
return isJPEG | isPNG;
165+
let isBMP = src.startsWith("data:image/bmp") || src.endsWith(".bmp");
166+
return isJPEG | isPNG | isBMP;
156167
}

content/options.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ async function loadImage(index) {
132132
}
133133

134134
i_previewthumb.src = images[index].url;
135-
l_previewfilename.textContent = images[index].file.name;
135+
l_previewfilename.textContent = changeExtensionIfNeeded(images[index].file.name);
136136
l_previeworiginalfilesize.textContent = browser.i18n.getMessage("preview.originalfilesize", [
137137
humanSize(images[index].file.size),
138138
]);
@@ -220,3 +220,13 @@ b_cancel.addEventListener("click", async () => {
220220
let thisWindow = await browser.windows.getCurrent();
221221
browser.windows.remove(thisWindow.id);
222222
});
223+
function changeExtensionIfNeeded(filename) {
224+
let src = filename.toLowerCase();
225+
//if it is a bmp we will save it as jpeg
226+
if (src.startsWith("data:image/bmp") || src.endsWith(".bmp")) {
227+
return src.replace("bmp", "jpg");
228+
}
229+
else
230+
return src;
231+
232+
}

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"name": "__MSG_extensionName__",
44
"description": "__MSG_extensionDescription__",
5-
"version": "5.4",
5+
"version": "5.5",
66
"applications": {
77
"gecko": {
88

modules/ShrunkedImage.jsm

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function ShrunkedImage(source, maxWidth, maxHeight, quality, options) {
4141
if (match) {
4242
this.basename = match[1];
4343
} else {
44-
match =/\/([\w.-]+\.(jpe?g|png))$/i.exec(this.sourceURI.spec);
44+
match =/\/([\w.-]+\.(jpe?g|png|bmp))$/i.exec(this.sourceURI.spec);
4545
if (match) {
4646
this.basename = match[1];
4747
}

0 commit comments

Comments
 (0)