我正在使用cropit裁剪图像。
<body>
<div class="image-editor">
<input type="file" class="cropit-image-input">
<!-- .cropit-image-preview-container is needed for background image to work -->
<div class="cropit-image-preview-container">
<div class="cropit-image-preview"></div>
</div>
<div class="image-size-label">
Resize image
</div>
<input type="range" class="cropit-image-zoom-input">
<button class="export">Save</button>
</div>
<script>
$(function() {
$('.image-editor').cropit({
exportZoom: 1.25,
imageBackground: true,
imageBackgroundBorderWidth: 10,
imageState: {
src: '../image/default-avatar.png'
}
});
$('.export').click(function() {
var imageData = $('.image-editor').cropit('export');
window.open(imageData);
});
});
</script>
</body>
我遇到了两个问题:
- 当我进行裁剪并单击“保存”按钮时,裁剪后的图像将在新窗口中打开。我希望它不应该在新窗口中打开,而是裁剪后的图像应该保存到相关的用户文件夹,例如:
ROOT_PATH.'user/upload/'.$row['用户名'].'/avatar/big/'
- 我还想将最新裁剪后的图像 URL 保存到 MySQL 数据库的
AvatarImage
列中。
在下面找到MySQL数据库信息:
数据库名称:ara
数据库用户:root
数据库密码:
数据库地址:127.0.0.1
最佳答案
您必须使用php对图像文件进行base64编码,并将图像保存到文件目录中, 请尝试欺骗现有的链接
How to create and save image to a website folder from a base64 encoded data/string using PHP
关于php - 将裁剪后的图像保存到本地服务器并将其 URL 保存到 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30161454/