TYPO3 FileReference converts tiff and bmp to gif - typo3

Uploading and using tiff or bmp files in TYPO3 and including them via f:image results them in beeing converted into gif files. Im using ImageMagick. I couldn't find anything about this issue but i wonder, because even uploading 100% jpg files results into double compression, while uploading bmp and tiff doesn't. Any ideas how to configure typo3 to convert tiff and bmp into jpg and not gif? Can't imagine that this is the right behavior.
edit:
i found out that the decision for the output format is done at
TYPO3\CMS\Core\Resource\Processing\AbstractGraphicalTask::determineTargetFileExtension
If there is no configuration given it will use gif or png for all non-jpg images. I overloaded the
\TYPO3\CMS\Core\Resource\Processing\ImageCropScaleMaskTask
which extends the AbstractGraphicalTask and rewrote the function to properly convert bmp and tiff.
Overwrite the default fal config in ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['processingTaskTypes']['Image.CropScaleMask'] = \i3\I3Content\Resource\Processing\ImageCropScaleMaskTask::class;
New function:
protected function determineTargetFileExtension() {
if (!empty($this->configuration['fileExtension'])) {
$targetFileExtension = $this->configuration['fileExtension'];
} else {
// explanation for "thumbnails_png"
// Bit0: If set, thumbnails from non-jpegs will be 'png', otherwise 'gif' (0=gif/1=png).
// Bit1: Even JPG's will be converted to png or gif (2=gif/3=png)
$targetFileExtensionConfiguration = $GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails_png'];
if ($this->getSourceFile()->getExtension() === 'jpg' || $this->getSourceFile()->getExtension() === 'jpeg') {
if ($targetFileExtensionConfiguration == 2) {
$targetFileExtension = 'gif';
} elseif ($targetFileExtensionConfiguration == 3) {
$targetFileExtension = 'png';
} else {
$targetFileExtension = 'jpg';
}
} else {
// check if a png or a gif should be created
if ($targetFileExtensionConfiguration == 1 || $this->getSourceFile()->getExtension() === 'png') {
$targetFileExtension = 'png';
} elseif($this->getSourceFile()->getExtension() === 'tif' || $this->getSourceFile()->getExtension() === 'tiff' || $this->getSourceFile()->getExtension() === 'bmp') {
$targetFileExtension = 'jpg';
} else {
// thumbnails_png is "0"
$targetFileExtension = 'gif';
}
}
}
return $targetFileExtension;
}

Check the $TYPO3_CONF_VARS[GFX][thumbnails_png] setting through install tool. There are various options how to convert different formats when resizing images.

Related

Regarding How to draw Unicode text in a PDF file

The following is excellent instruction. This is helpful information.
https://www.syncfusion.com/kb/11976/how-to-draw-unicode-text-in-a-pdf-file-using-google-fonts-package
However, I can't understand how to create the TTF file data by the getFont method. There is no "writeAsBytes" statement. This means the TTF file is always empty.
In what cases is the following condition TRUE?
// Line 11 of getFont
if (fontBytes != null && fontBytes.isNotEmpty) {
In the below KB documentation, we are getting the font from the Google fonts package in Flutter. The Google fonts package fetches the font files via HTTP at runtime and caches them in the application’s file system. In this article, we have used cached files to render the Unicode text in a PDF document. The reported problem is due to the Flutter Google fonts package being updated. And please make sure the device/emulator internet connectivity is properly connected or not. If not, please connect to the internet and try the below code snippet on your end and let us know the result.
Please refer to the below code snippet,
Future<PdfFont> getFont(TextStyle style) async {
//Get the external storage directory
Directory directory = await getApplicationSupportDirectory();
//Create an empty file to write the font data
File file = File('${directory.path}/${style.fontFamily}.ttf');
if (!file.existsSync()) {
List<FileSystemEntity> entityList = directory.listSync();
for (FileSystemEntity entity in entityList) {
if (entity.path.contains(style.fontFamily!)) {
file = File(entity.path);
break;
}
}
}
List<int>? fontBytes;
//Check if entity with the path exists
if (file.existsSync()) {
fontBytes = await file.readAsBytes();
}
if (fontBytes != null && fontBytes.isNotEmpty) {
//Return the google font
return PdfTrueTypeFont(fontBytes, 12);
} else {
//Return the default font
return PdfStandardFont(PdfFontFamily.helvetica, 12);
}
}

Upload image to firebase storage from React Dropzone (gives invalid Image)

I am using React Dropzone to upload files from React to firebase as shown below:
const onDrop = useCallback((acceptedFiles, fileRejections) => {
//Check if file type is image
//Check if file size < 5MB
//Upload
if (fileRejections.length > 0) {
setError(true);
} else setError(false);
if (acceptedFiles.length > 0) {
const file = acceptedFiles[0];
console.log(file);
setFile({
...file,
preview: URL.createObjectURL(file),
});
setFileUploaded(true);
}
}, []);
and this is my upload handler:
const handleImageUpload = () => {
//Upload Image to Firebase
//Check if file exists
if (file !== null || file !== undefined) {
const storageRef = ref(
Client.storage,
`/db-dev/user-metadata/portfolio/images/first-image.jpg`
);
console.log('Process begins');
uploadBytes(storageRef, file).then((snapshot) => {
console.log('Uploaded a blob or file!');
});
}
};
these two things do the work but I believe for some reason they're not encoding or decoding the image as in firebase storage folder I see image as invalid image.
Can someone help me to understand where things are going wrong? (To make sure file is loaded properly, I am also viewing the file using: preview: URL.createObjectURL(file), and it loads correctly in browser.
For file upload I am following the latest firebase documentation
It sets file type to octet-stream not sure what that means:
Edit 1: I tried to set metadata to image/jpeg:
uploadBytes(storageRef, file, {
contentType: 'image/jpeg',
}).then((snapshot) => {
console.log('Uploaded a blob or file!');
});
But now it shows:
The problem was in this step:
setFile({
...file,
preview: URL.createObjectURL(file),
});
for some reason it wasn't spreading correctly. I changed it to:
setFile({
file:file,
preview: URL.createObjectURL(file),
});
and the upload function to:
const handleImageUpload = () => {
//Upload Image to Firebase
//Check if file exists
if (file !== null || file !== undefined) {
const storageRef = ref(
Client.storage,
`/db-dev/user-metadata/portfolio/images/first-image.jpg`
);
console.log('Process begins');
uploadBytes(storageRef, file.file, {
contentType: file.file.type,
}).then((snapshot) => {
console.log('Uploaded a blob or file!');
});
}
};
and then it worked fine. Although this was a really silly thing on my part but hope this helps someone in future

Getting bytearray from PdfDictionary

Please refer to this picture below taken from itext url https://itextpdf.com/en/resources/faq/technical-support/itext-5/how-add-alternative-text-image-tagged-pdf. I am trying to get the bytearray of the images in the pdf, while traversing all the branches, looking for structural element marked as /Figure. Goal is to insert a tag (alternate text) to the image as well get the byte array of that specific image to which I am adding the alternate text.
Here is the code
static void manipulate(PdfDictionary element)
{
if (element == null)
return;
var t = element.GetBytes();
if (PdfName.FIGURE.Equals(element.Get(PdfName.S)))
{
element.Put(PdfName.ALT, new PdfString("Figure without ALT"));
var byteaarray = element.GetBytes(); //// Here bytearray is null
}
var kids = element.GetAsArray(PdfName.K);
if (kids == null)
return;
for(int i = 0; i < kids.Size; i++)
{
manipulate(kids.GetAsDict(i));
}
}
The program successfully adds alternate text "Figure without ALT" to all the images. However, the bytes of that figure is null.
Can you please tell what am I doing wrong here?
Thank you.

Typo3/Typoscript: get data from (page) media ressources

I'm using Typo3 6.2.15 and want to upload some files at page->ressources->media like jpegs, mp4s, pngs...
To switch the output of the different filetypes, I tried it with the following script without success:
HEADER = CASE
HEADER {
key.data = levelmedia: -1, slide
key.listNum = 0
key.split {
token = .
returnKey = 1
}
jpg = TEXT
jpg.value = test
}
Has anybody an idea whats the problem?

ASP.NET Connection Reset on Upload

I'm running into a problem with my app (ASP.NET MVC 2) where I can't upload files (images in my case). I've changed the web.config to accept up to 20MB, and I'm trying to upload a file that's only 3MB.
The app itself has two ways to upload. The initial upload which starts a Gallery and then an additional upload to append to a Gallery.
The initial works like a charm, but the appending one fails with no explanation. Even if I re-upload the initial image as an append it still fails.
I'm a little stuck on this so I would appreciate any help you guys can offer.
Thanks in advance!
EDIT
If I "hack" the form with Firebug and direct it to the initial upload Url it works, but when it's directing to the Url it should be posting to it fails...
EDIT 2
Per Rob's request, here's the code handling the initial gallery and appending image:
[HttpPost, ValidateAntiForgeryToken]
public RedirectToRouteResult PutGallery( // Move to Ajax
[Bind(Prefix = "Gallery", Include = "ClubId,EventId,RHAccountId,RHCategoryId,Year")] Gallery Gallery,
HttpPostedFileBase File) {
if (ModelState.IsValid && (File.ContentLength > 0)) {
if (Gallery.RHAccountId > 0) {
Gallery.RHUser = this.fdc.RHAccounts.Single(
a =>
(a.RHAccountId == Gallery.RHAccountId)).RHUser;
} else {
if (!this.fdc.RHUsers.Any(
u =>
(u.User.Name == Gallery.Username))) {
if (!this.fdc.Users.Any(
u =>
(u.Name == Gallery.Username))) {
Gallery.RHUser = new RHUser() {
User = new User() {
Name = Gallery.Username
}
};
} else {
Gallery.RHUser = new RHUser() {
User = this.fdc.Users.Single(
u =>
(u.Name == Gallery.Username))
};
};
} else {
Gallery.RHUser = this.fdc.RHUsers.Single(
u =>
(u.User.Name == Gallery.Username));
};
};
Image Image = new Image() {
Gallery = Gallery
};
this.fdc.Galleries.InsertOnSubmit(Gallery);
this.fdc.Images.InsertOnSubmit(Image);
this.fdc.SubmitChanges();
Files.Save(Image.ImageId, File);
return RedirectToAction("Default", "Site");
} else {
return RedirectToAction("Default", "Site");
};
}
[HttpPost, ValidateAntiForgeryToken]
public RedirectToRouteResult PutImage(
[Bind(Prefix = "Image", Include = "GalleryId")] Image Image,
HttpPostedFileBase File) {
Gallery Gallery = this.fdc.Galleries.Single(
g =>
(g.GalleryId == Image.GalleryId));
if (File.ContentLength > 0) {
this.fdc.Images.InsertOnSubmit(Image);
this.fdc.SubmitChanges();
Files.Save(Image.ImageId, File);
};
return RedirectToAction("Gallery", "Site", new {
Category = Gallery.RHCategory.Category.EncodedName,
GalleryId = Gallery.GalleryId
});
}
SIDENOTE:
Could Cassini, VS 2010's built in web server, be the cause?
Ok, so I figured it out, it only took a lengthy install of IIS locally on my machine + the configuration, to have it tell me that I miss-spelled controller as controlls in the routes.
Really annoying that it took all of that to get the real error, so Cassini was partially at fault...
So, the moral of the story is, make sure you spell everything correctly.