小编rod*_*ini的帖子

Fabric.js canvas.toDataURL()由Ajax发送给PHP

当我需要创建一个透明背景的图像时,我遇到了问题.我仍然不知道问题是使用fabricjs还是使用php.当我发送带有彩色背景的图像时,一切正常.发送带透明背景的图像时会出现问题.生成的图像使用黑色背景创建.所以,让我解释一下:当用户点击"保存"按钮时,我将画布的字符串表示发送到服务器端的php,以生成画布的图像.所以我使用follow函数通过Ajax发送画布的字符串表示形式(jQuery的POST函数):


    function sendStringRepresentation(){
        var strDataURI = canvas.toDataURL();
        strDataURI = strDataURI.substr(22, strDataURI.length);

        $.post("action/createImage.php",
        { 
            str: strDataURI
        },
        function(data){
            if(data == "OK"){
                $("#msg").html("Image created.");
        }
        else{
            $("#msg").html("Image not created.");
            }
        });
    }

在PHP文件中我使用以下代码生成图像:


    // createImage.php

    $data = base64_decode($_POST["str"]);

    $urlUploadImages = "../uploads/img/";
    $nameImage = "test.png";

    $img = imagecreatefromstring($data);

    if($img) {
        imagepng($img, $urlUploadImages.$nameImage, 0);
        imagedestroy($img);

        // [database code]

        echo "OK";
    }
    else {
        echo 'ERROR';
    }

同样,问题只在于背景透明画布.彩色背景一切正常.

javascript php canvas fabricjs

5
推荐指数
1
解决办法
9265
查看次数

在ItemView Marionette.js中使用jquery获取ui元素的正确方法

我正在学习Marionette.js,并想知道使用jQuery操作ui元素的正确方法.在我的LoginItemView中,我声明了ui元素和一个显示无效登录错误消息的函数:


ui: {
  username: "#username",
  password: "#password",
  btnLogin: "#btnDoLogin",
  messageContainer: "#messageContainer"
},
displayMessage: function() {
  // show error message
  $(this.ui.messageContainer.selector).show();
},

我也尝试过:


  $(this.ui.messageContainer[0]).show();

但邮件永远不会显示.
这是模板中的containerMessage代码.

<div class="alert alert-danger alert-dismissable login-message-display" id="#messageContainer" style="display: none;">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    <strong>Error!</strong> Username and/or password incorrect!
</div>
Run Code Online (Sandbox Code Playgroud)

javascript jquery marionette

4
推荐指数
1
解决办法
2475
查看次数

检查数据库是否支持使用FireDac的事务

如何使用FireDac组件检查DBMS是否支持事务?
通常,我使用类似下面的代码,使用dbExpress在我的DAO类中执行事务.

...
connection: TSQLConnection;
dbxTransaction: TDBXTransaction;
... 

if (connection.TransactionsSupported) AND ((not connection.InTransaction) OR (connection.MultipleTransactionsSupported)) then
begin
    dbxTransaction := connection.BeginTransaction(TDBXIsolations.ReadCommitted);
end;
Run Code Online (Sandbox Code Playgroud)

那么,我在dbExpress中使用的FireDac中的通讯属性是什么:
TransactionsSupported
InTransaction
MultipleTransactionsSupported

提前致谢.

delphi dbexpress firedac delphi-xe7

3
推荐指数
1
解决办法
615
查看次数