Support PNG, JPEG, BMP, WEBP export formats by change of "Export to PNG" menu item into "Export" with its own pull-down dialog (and a HTML5 range type input element for "quality" selection for JPEG or WEBP files), including changes for the server_opensave extension; change locale key from "export_png" to "export_img" and change the corresponding localized strings (currently CS, DE, ES, FR, IT, NL, PT-BR, RO, SK, all reset to English to avoid translation errors); within the setCustomHandlers() API, deprecate "pngsave" in favor of "exportImage" (chosen to avoid just using the simpler but reserved JS keyword "export") including use within the server_opensave extension; a few JSLint-friendly changes
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2602 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -11,7 +11,7 @@ svgEditor.addExtension("server_opensave", {
|
||||
callback: function() {
|
||||
|
||||
var save_svg_action = 'extensions/filesave.php';
|
||||
var save_png_action = 'extensions/filesave.php';
|
||||
var save_img_action = 'extensions/filesave.php';
|
||||
|
||||
// Create upload target (hidden iframe)
|
||||
var target = $('<iframe name="output_frame" src="#"/>').hide().appendTo('body');
|
||||
@@ -32,8 +32,10 @@ svgEditor.addExtension("server_opensave", {
|
||||
.appendTo('body')
|
||||
.submit().remove();
|
||||
},
|
||||
pngsave: function(win, data) {
|
||||
var issues = data.issues;
|
||||
exportImage: function(win, data) {
|
||||
var issues = data.issues,
|
||||
mimeType = data.mimeType,
|
||||
quality = data.quality;
|
||||
|
||||
if(!$('#export_canvas').length) {
|
||||
$('<canvas>', {id: 'export_canvas'}).hide().appendTo('body');
|
||||
@@ -43,7 +45,7 @@ svgEditor.addExtension("server_opensave", {
|
||||
c.width = svgCanvas.contentW;
|
||||
c.height = svgCanvas.contentH;
|
||||
canvg(c, data.svg, {renderCallback: function() {
|
||||
var datauri = c.toDataURL('image/png');
|
||||
var datauri = quality ? c.toDataURL(mimeType, quality) : c.toDataURL(mimeType);
|
||||
|
||||
var uiStrings = svgEditor.uiStrings;
|
||||
var note = '';
|
||||
@@ -63,9 +65,10 @@ svgEditor.addExtension("server_opensave", {
|
||||
|
||||
var form = $('<form>').attr({
|
||||
method: 'post',
|
||||
action: save_png_action,
|
||||
action: save_img_action,
|
||||
target: 'output_frame'
|
||||
}) .append('<input type="hidden" name="output_png" value="' + datauri + '">')
|
||||
}) .append('<input type="hidden" name="output_img" value="' + datauri + '">')
|
||||
.append('<input type="hidden" name="mime" value="' + mimeType + '">')
|
||||
.append('<input type="hidden" name="filename" value="' + filename + '">')
|
||||
.appendTo('body')
|
||||
.submit().remove();
|
||||
|
||||
@@ -8,27 +8,35 @@
|
||||
* Copyright(c) 2010 Alexis Deveria
|
||||
*
|
||||
*/
|
||||
|
||||
$allowedMimeTypesBySuffix = array(
|
||||
'svg' => 'image/svg+xml',
|
||||
'png' => 'image/png',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'bmp' => 'image/bmp',
|
||||
'webp' => 'image/webp'
|
||||
);
|
||||
|
||||
$mime = !isset($_POST['mime']) || !in_array($_POST['mime'], $allowedMimeTypesBySuffix) ? 'image/svg+xml' : $_POST['mime'];
|
||||
|
||||
if(!isset($_POST['output_svg']) && !isset($_POST['output_png'])) {
|
||||
if (!isset($_POST['output_svg']) && !isset($_POST['output_img'])) {
|
||||
die('post fail');
|
||||
}
|
||||
|
||||
$file = '';
|
||||
|
||||
$suffix = isset($_POST['output_svg'])?'.svg':'.png';
|
||||
$suffix = '.' . array_search($mime, $allowedMimeTypesBySuffix);
|
||||
|
||||
if(isset($_POST['filename']) && strlen($_POST['filename']) > 0) {
|
||||
if (isset($_POST['filename']) && strlen($_POST['filename']) > 0) {
|
||||
$file = $_POST['filename'] . $suffix;
|
||||
} else {
|
||||
$file = 'image' . $suffix;
|
||||
}
|
||||
|
||||
if($suffix == '.svg') {
|
||||
$mime = 'image/svg+xml';
|
||||
if ($suffix == '.svg') {
|
||||
$contents = rawurldecode($_POST['output_svg']);
|
||||
} else {
|
||||
$mime = 'image/png';
|
||||
$contents = $_POST['output_png'];
|
||||
$contents = $_POST['output_img'];
|
||||
$pos = (strpos($contents, 'base64,') + 7);
|
||||
$contents = base64_decode(substr($contents, $pos));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user