Skip to content

Commit

Permalink
Merge pull request #208 from l-atelier-des-chercheurs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
louis-ev authored Nov 26, 2016
2 parents 98b2ab5 + 815347e commit 7d2c313
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 94 deletions.
108 changes: 43 additions & 65 deletions app/bin/dodoc-media.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ var mm = require('marky-mark');
var ffmpeg = require('fluent-ffmpeg');

// only load sharp if not in electron (need to find how to make it work eventually)
if(process.versions['electron'] === undefined)
var sharp = require('sharp');
var sharp = require('sharp');

var dodoc = require('../dodoc');
var dodocAPI = require('./dodoc-api');
Expand All @@ -23,8 +22,9 @@ var dodocMedia = (function() {
listOneMedia : function(slugFolderName, slugProjectName, singleMediaFolderPath, mediaName) { return listOneMedia(slugFolderName, slugProjectName, singleMediaFolderPath, mediaName); },
createNewMedia : function(newMediaData) { return createNewMedia(newMediaData); },
editMediaMeta : function(editMediaData) { return editMediaMeta(editMediaData); },
createThumbnails : function(videoPath, videoFilename, pathToMediaFolder) { return createThumbnails(videoPath, videoFilename, pathToMediaFolder);},
createThumbnails : function(videoPath, videoFilename, pathToMediaFolder) { return createThumbnails(videoPath, videoFilename, pathToMediaFolder);},
deleteOneMedia : function(slugFolderName, slugProjectName, mediaFolder, mediaName) { return deleteOneMedia(slugFolderName, slugProjectName, mediaFolder, mediaName); },
makeImageFromData : function(imageBufferData, pathToFile) { return makeImageFromData(imageBufferData, pathToFile); },
};

/***************************************************************************************************/
Expand Down Expand Up @@ -102,34 +102,31 @@ var dodocMedia = (function() {
pathToFile = path.join(mediaPath, newFileName);

var imageBuffer = dodocAPI.decodeBase64Image( newMediaData.mediaData);
fileExtension = '.png';
var imagePath = pathToFile + fileExtension;
dev.logverbose('Will store this photo at path: ' + pathToFile + fileExtension);

fs.writeFile(imagePath, imageBuffer.data, function(err) {
if (err)
reject( err);

_makeImageOptimizations(pathToFile, fileExtension).then(function(imagePath) {
var thumbPath = pathToFile + '-' + dodoc.thumbSuffix + '.jpeg';
_makeImageThumb(imagePath, thumbPath).then(function(err) {
if( err) { dev.error('--> Failed to make a thumbnail for a photo! Error: ', err); }
_createMediaMeta( newMediaType, pathToFile, newFileName).then( function( mdata) {
mdata.slugFolderName = slugFolderName;
mdata['slugProjectName'] = slugProjectName;
mdata['mediaFolderPath'] = mediaFolder;
console.log('Just created a photo, its meta is ' + JSON.stringify( mdata, null, 4));
resolve( mdata);
}, function(error) {
dev.error('Failed to create meta for photo! Error: ', error);
reject( 'failed to create meta for photo');
});
dev.logverbose('Will store this photo at path: ' + pathToFile);

makeImageFromData(imageBuffer.data, pathToFile)
.then(function(imagePath) {
var thumbPath = pathToFile + '-' + dodoc.thumbSuffix + '.jpeg';
_makeImageThumb(imagePath, thumbPath)
.then(function(err) {
if( err) { dev.error('--> Failed to make a thumbnail for a photo! Error: ', err); }
_createMediaMeta( newMediaType, pathToFile, newFileName).then( function( mdata) {
mdata.slugFolderName = slugFolderName;
mdata['slugProjectName'] = slugProjectName;
mdata['mediaFolderPath'] = mediaFolder;
console.log('Just created a photo, its meta is ' + JSON.stringify( mdata, null, 4));
resolve( mdata);
}, function(error) {
dev.error('Failed to create meta for photo! Error: ', error);
reject( 'failed to create meta for photo');
});

});

}, function(error) {
dev.error("Failed to save image! Error: ", error);
reject();
});


break;
case 'video':
var mediaPath = _getMediaPath( slugFolderName, slugProjectName, mediaFolder);
Expand Down Expand Up @@ -176,7 +173,7 @@ var dodocMedia = (function() {
var frameRate = newMediaData.frameRate || 4;

// ask ffmpeg to make a video from the cache images
var proc = new ffmpeg({ "source" : pathToFile + '/%*.png'})
var proc = new ffmpeg({ "source" : pathToFile + '/%*.jpeg'})
// using 12 fps
.withFpsInput(frameRate)
.withVideoCodec('libvpx')
Expand Down Expand Up @@ -379,6 +376,23 @@ var dodocMedia = (function() {
});
}

// receives base64data and a path to filename (without ext)
function makeImageFromData(imageBufferData, pathToFile) {
return new Promise(function(resolve, reject) {
var imagePath = pathToFile + '.jpeg';
dev.logverbose('Now using sharp to store new image.');
sharp(imageBufferData)
.rotate()
.withMetadata()
.toFormat(sharp.format.jpeg)
.quality(90)
.toFile(imagePath, function(err, info) {
dev.logverbose('Image has been saved, resolving its path.');
resolve(imagePath);
});
});
}


/***************************************************************************************************/
/******************************************** private functions ************************************/
Expand Down Expand Up @@ -528,42 +542,6 @@ var dodocMedia = (function() {
return cleanMediaName;
}

function _makeImageOptimizations(pathToFile, fileExtension) {
return new Promise(function(resolve, reject) {
dev.logverbose("Optimizing images at path: " + pathToFile);

var optimizedFileExtension = '.jpg';
var optimizedPhotoFileName = pathToFile + '-optim' + optimizedFileExtension;
var imagePath = pathToFile + fileExtension;

if(typeof sharp === 'undefined') {
resolve(imagePath);
}

sharp(imagePath)
.rotate()
.withMetadata()
.toFormat(sharp.format.jpeg)
.quality(90)
.toFile(optimizedPhotoFileName, function(err, info) {
if(err) {
dev.error( '--> Couldn’t optimize photo! Error: ', err);
resolve(imagePath);
}
fs.unlink(imagePath, function(err) {
if (err) { dev.error('Error while trying to remove original image.'); }

var imagePath = pathToFile + optimizedFileExtension;
fs.rename(optimizedPhotoFileName, imagePath, function(err) {
if (err) { dev.error('Error while trying to rename optimized image.'); }
resolve(imagePath);
});
});

});
});
}

function _makeImageThumb(imagePath, thumbPath) {
return new Promise(function(resolve, reject) {
dev.logverbose("Making a thumb at thumbPath: " + thumbPath);
Expand All @@ -576,7 +554,7 @@ var dodocMedia = (function() {
.max()
.withoutEnlargement()
.withMetadata()
.toFormat(sharp.format.jpeg)
.toFormat('jpeg')
.quality(70)
.toFile(thumbPath)
.then(function() {
Expand Down
29 changes: 21 additions & 8 deletions app/client/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7763,6 +7763,16 @@ body.index #container {
100% {
opacity: 1; } }

.gu-mirror .mediaContent {
width: 100%;
height: 100%; }
.gu-mirror .mediaContent > * {
object-fit: scale-down;
width: 100%;
height: 100%; }
.gu-mirror .mediaContent audio {
display: none; }

.gu-mirror .button-wrapper_flagMedia {
display: none; }

Expand Down Expand Up @@ -8151,15 +8161,16 @@ body.capture .content-wrapper:after {
z-index: 2;
margin-bottom: 25px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
max-width: 46%;
max-width: 48%;
width: 80vh;
height: 80vh;
height: calc(100vh - 200px);
padding: 8px;
left: 50%;
transform: translate3d(-50%, 0, 0);
transition: transform .4s ease-out, background-color .1s; }
body[data-state="expanded"] .captureLeft {
transform: translate3d(-104%, 0, 0); }
transform: translate3d(-102%, 0, 0); }
body.is--fullscreen .captureLeft {
width: 100%;
left: 0 !important;
Expand Down Expand Up @@ -8306,7 +8317,8 @@ body.capture .content-wrapper:after {
.captureLeft #canvas-audio {
display: none;
width: 100%;
height: 100%; }
height: 100%;
object-fit: scale-down; }
.captureLeft .full-screen-wrapper {
position: absolute;
top: 0;
Expand Down Expand Up @@ -8344,6 +8356,8 @@ body.capture .content-wrapper:after {
.captureLeft .recording-feedback .time-feedback {
display: inline-block;
vertical-align: middle;
font-variant: small-caps;
text-transform: lowercase;
color: currentColor;
margin-left: 8px; }

Expand All @@ -8366,14 +8380,15 @@ body.capture .content-wrapper:after {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
padding: 8px;
height: 80vh;
max-width: 41%;
height: calc(100vh - 280px);
max-width: 48%;
width: 80vh;
left: 50%;
transform: translate3d(-50%, 0, 0);
transition: transform .4s ease-out, opacity .6s ease-out; }
body[data-state="expanded"] .captureRight {
opacity: 1;
transform: translate3d(4%, 0, 0); }
transform: translate3d(2%, 0, 0); }
.captureRight .flash {
height: 100%;
background-color: #FFF;
Expand Down Expand Up @@ -8466,16 +8481,14 @@ body.capture .content-wrapper:after {
transition: opacity .6s ease-out;
opacity: 0; }
.captureRight .preview_stopmotion .preview_stopmotion--container .stopmotion_lastImagePreview .image_count {
font-size: 80%;
font-variant: small-caps;
text-transform: lowercase;
position: absolute;
z-index: 1200;
bottom: 0;
left: 0;
padding: 8px;
text-shadow: 0px 0px 5px black;
color: white; }
color: #4BC0B4; }
.captureRight .preview_stopmotion .preview_stopmotion--container .stopmotion_lastImagePreview .image_count::after {
counter-increment: compteListe 1;
content: counter(compteListe) " "; }
Expand Down
2 changes: 1 addition & 1 deletion app/client/js/modules/_capture-audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var equalizer = (function() {
// Global Variables for Drawing
var column = 0;
var canvasWidth = 720;
var canvasHeight = 720;
var canvasHeight = 360;
var ctx;

var API = {
Expand Down
18 changes: 17 additions & 1 deletion app/client/sass/_bibli.scss
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ body.bibli {
overflow: hidden;
}


.media.gu-transit .mediaContent {
opacity: 1;
background-color: $c-images;
box-shadow: none;


> * {
opacity: 0;
}
Expand Down Expand Up @@ -267,10 +267,26 @@ body.bibli {

// class ajoutée aux éléments draggés. En bas du dom
.gu-mirror {
.mediaContent {
width: 100%;
height: 100%;

> * {
object-fit:scale-down;
width: 100%;
height: 100%;

}
audio {
display: none;
}
}
.button-wrapper_flagMedia {
display: none;
}
}


.button-wrapper_flagMedia {
display: none;
}
Expand Down
18 changes: 13 additions & 5 deletions app/client/sass/_capture.scss
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ body.capture{
}

$buttonBar: $margin + 64px;
$t-decalageDuCentre: 4%;
$t-decalageDuCentre: 2%;

.captureLeft {

Expand All @@ -278,7 +278,10 @@ $t-decalageDuCentre: 4%;

max-width: 50% - $t-decalageDuCentre;
width: 80vh;

height: 80vh;
height: calc(100vh - 200px);

padding: $margin/2;

left: 50%;
Expand Down Expand Up @@ -525,6 +528,8 @@ $t-decalageDuCentre: 4%;
display: none;
width: 100%;
height: 100%;
object-fit: scale-down;

}

.full-screen-wrapper {
Expand Down Expand Up @@ -592,6 +597,9 @@ $t-decalageDuCentre: 4%;
display: inline-block;
vertical-align: middle;

font-variant: small-caps;
text-transform: lowercase;

color: currentColor;
margin-left: $margin/2;
}
Expand Down Expand Up @@ -622,7 +630,9 @@ $t-decalageDuCentre: 4%;
padding: $margin/2;

height: 80vh;
max-width: 45% - $t-decalageDuCentre;
height: calc(100vh - 280px);

max-width: 50% - $t-decalageDuCentre;
width: 80vh;

left: 50%;
Expand Down Expand Up @@ -764,7 +774,6 @@ $t-decalageDuCentre: 4%;
transition: opacity .6s ease-out;

.image_count {
font-size: 80%;
font-variant: small-caps;
text-transform: lowercase;

Expand All @@ -774,8 +783,7 @@ $t-decalageDuCentre: 4%;
left: 0;
padding: $margin/2;

text-shadow: 0px 0px 5px black;
color: white;
color: $bleuvert;

&::after {
counter-increment: compteListe 1;
Expand Down
Loading

0 comments on commit 7d2c313

Please sign in to comment.