[英]PHP image cropper with Javascript
I am creating an image cropper. 我正在创建图像裁切器。 I have the following declared in PHP.
我在PHP中声明了以下内容。 This is the image that is going to be cropped.
这是将要裁剪的图像。
$src_name = 'image.jpg';
After declaring this, I have a simple javascript image switcher. 声明之后,我有一个简单的javascript图像切换器。
<script language="javascript" type="text/javascript">
function changebg(my)
{
document.getElementById("cropframe").style.backgroundImage ='url('+ my.src +')';
document.getElementById("imglayer").style.backgroundImage ='url('+ my.src +')';
}
</script>
<img src="imagename1" width="50" height="50" onclick="changebg(this)" >
<img src="imagename2" width="50" height="50" onclick="changebg(this)" >
<div id="cropframe" style="background-image: url('<?=$src_original ?>')"></div>
<div id="imglayer" style="width: 100%; height: 500px; padding: 1px; background-position: top left; background-image: url('<?=$src_original ?>')">
Then I have the form where the cropping of the image takes place. 然后,我具有裁剪图像的形式。
<form name="crop" method="post" action="crop-action.php">
<p><button onclick="cwcrop_handler.doCrop()">Crop</button></p>
Is it possible for me to change the image that is going to be cropped? 我可以更改将要裁剪的图像吗? I understand that PHP takes place server side.
我了解PHP是在服务器端进行的。 But can I have the new imagename passed into the "crop-action.php" so the correct image is cropped?
但是我可以将新的图像名称传递到“ crop-action.php”中,以便裁剪正确的图像吗? Thank you!
谢谢!
If i understand right you will make the crop server-side with php, and only take input from the user via javascript... 如果我理解正确,您将使用php来裁剪服务器端,并且仅通过javascript接收用户的输入...
I'm not sure how you indent the user to make the crop, but a simple solution is to add a post-variable to the form. 我不确定您如何缩编用户以进行裁剪,但是一个简单的解决方案是在表单中添加后变量。 You could simply do that with something like this...
你可以简单地做, 像这样的东西...
HTML: HTML:
<input id="fileIdentifier" name="fileIdentifier" type="hidden" value="identity">
Then fetch the input with javascript when the user start editing, and change the value of the input element. 然后在用户开始编辑时使用javascript获取输入,并更改输入元素的值。 JS:
JS:
var fileID = doument.getElementByID("fileIdentifier");
fileID.value = imageIdentifierValue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.