Answer the question
In order to leave comments, you need to log in
How to convert heic format to jpg using js or php?
Guys, has anyone already tried to convert these formats?
I'm trying to convert heic format to one of the popular ones (jpg, png). I do everything as in the official repository of this format:
HEIFReader reader = new HEIFReader('test.heic');
reader.requestFileInfo(function(payload) {
if(payload.success !== true) {
console.error("Could not read file:", url);
} else {
var fileInfo = payload;
console.log("FileInfo contents:", fileInfo);
}
});
// META file containing still images
if (fileInfo.rootLevelMetaBoxProperties) {
var masterContextId = fileInfo.rootLevelMetaBoxProperties.contextId;
var masterItemIds = [];
var imageFeaturesMap = fileInfo.rootLevelMetaBoxProperties.imageFeaturesMap;
for (i in imageFeaturesMap) {
if (imageFeaturesMap.hasOwnProperty(i) && imageFeaturesMap[i].isMasterImage === true) {
masterItemIds.push(parseInt(i));
}
}
console.log("Master images in the file:", masterItemIds);
}
/** Request decoded image data for given item id's.
* @param {number} contextId Id of the context.
* @param {Array.<number>} itemIds Array of item id's to be decoded.
* @param {function} callback Callback function that receives the payload as a parameter. */
this.requestImageData = function (contextId, itemIds, callback) {
console.log(_name + ": REQUEST IMAGE DATA: " + itemIds);
if (itemIds.constructor !== Array) {
itemIds = [itemIds];
}
if (itemIds.length < 1) {
return;
}
var stream = new Uint8Array();
var decodeIds = [];
var dependencies = {};
var displayDependencies = {};
for (var i = 0; i < itemIds.length; i++) {
var refs = self._heifReader.getItemDecodeDependencies(contextId, itemIds[i]);
for (var j = 0; j < refs.length; j++) {
if (refs[j] !== itemIds[i]) {
// Add dependency data to the stream if the id is not already listed in dependencies
if(!(refs[j] in dependencies) && !(refs[j] in displayDependencies)) {
dependencies[refs[j]] = true;
stream = _appendBuffer(stream, new Uint8Array(self._heifReader.getItemDataWithDecoderParameters(contextId, refs[j])));
decodeIds.push(refs[j]);
}
} else {
// Item has itself as dependency => we want to display that item despite being a dependency
displayDependencies[refs[j]] = true;
}
}
}
// Add data of the actual items to the stream (that already contains dependency data)
for (i = 0; i < itemIds.length; i++) {
stream = _appendBuffer(stream, new Uint8Array(self._heifReader.getItemDataWithDecoderParameters(contextId, itemIds[i])));
decodeIds.push(itemIds[i]);
}
var payload = new Payload(true, [], 0, 0);
self._hevcDecoder.pushRequestContext(new RequestContext(callback, decodeIds, stream, dependencies, payload));
self._hevcDecoder.decode();
};
self._hevcDecoder.decode();
HevcDecoder decodes hevc encoded stream to RGBA image data.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question