PHP,GD库,图像旋转(PHP, GD library, Image rotation)
我是GD的新手,我正在尝试构建一个旋转图像的简单脚本,但是我收到以下错误:
Warning: imagejpeg() expects parameter 1 to be resource, boolean given in C:\wamp\www\uploading.php on line 6
这是我的PHP:
$imgsrc = 'uploaded/Tulips.jpg'; $img = imagecreatefromjpeg($imgsrc); $imgRotated = imagerotate($img,45,-1); imagejpeg($imgRotated,"uploaded/myPicRotated.jpg",100);
这有什么问题吗?
更新:我在
imagerotate($img,45,0)
0替换为0并且它工作正常。 但是我得到了黑色背景色。 如何将其更改为白色?I'm new to GD and I'm trying to build a simple script that rotates an image, but I'm getting the following error:
Warning: imagejpeg() expects parameter 1 to be resource, boolean given in C:\wamp\www\uploading.php on line 6
Here is my php:
$imgsrc = 'uploaded/Tulips.jpg'; $img = imagecreatefromjpeg($imgsrc); $imgRotated = imagerotate($img,45,-1); imagejpeg($imgRotated,"uploaded/myPicRotated.jpg",100);
is there something wrong with this?
UPDATE : I replaced -1 with 0 in
imagerotate($img,45,0)
and it works fine. However I get a black background color. How do I change it to be a white color?
原文:https://stackoverflow.com/questions/26550661
最满意答案
感谢Yuriy的意见,我能够提出一个解决方案。
基本上,我创建的代码将在页面首次加载时定义我的函数。 此外,我注册了我的自定义函数,以在每次ajax请求后重新定义我的函数。 鉴于我将此代码放在MasterPage上,我能够使其在所有应用程序中运行。
这是代码:
MasterPage.aspx是一个简单的Html页面,其ContentPlaceHolders和ScriptManager位于表单标签的正下方。 另外,我必须在页面顶部(head标签)添加对“Utils.js”的引用。
MasterPage.aspx.cs
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!Page.ClientScript.IsStartupScriptRegistered("jsDefineFunction")) Page.ClientScript.RegisterStartupScript(Page.GetType(), "jsDefineFunction", "defineValidationFunction();", true); if (!Page.ClientScript.IsStartupScriptRegistered("jsDefineEndRequestFunction")) Page.ClientScript.RegisterStartupScript(Page.GetType(), "jsDefineEndRequestFunction", "Sys.WebForms.PageRequestManager.getInstance().add_endRequest(defineValidationFunction);", true); } }
Utils.js
function defineValidationFunction() { var ValidatorConvert = function (op, dataType, val) { //>>Consider everything as valid (client side) return op.toString(); } }
有了这个,我的代码适用于使用MasterPage的所有页面。 代码将不断覆盖我的验证功能。 有一点开销,但我无法想出另一种方式。
Thanks to Yuriy's input, I was able to come up with a solution.
Basically, I created code that will define my function when the page first load. Also, I registered my custom function to redefine my function after every ajax request. Given that I put this code on a MasterPage I'm able to make it work across all the application.
Here's the code:
MasterPage.aspx is a simple Html page with its ContentPlaceHolders and the ScriptManager right below the form tag. Also, I had to place a reference to my "Utils.js" at the top of the page (head tag).
MasterPage.aspx.cs
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!Page.ClientScript.IsStartupScriptRegistered("jsDefineFunction")) Page.ClientScript.RegisterStartupScript(Page.GetType(), "jsDefineFunction", "defineValidationFunction();", true); if (!Page.ClientScript.IsStartupScriptRegistered("jsDefineEndRequestFunction")) Page.ClientScript.RegisterStartupScript(Page.GetType(), "jsDefineEndRequestFunction", "Sys.WebForms.PageRequestManager.getInstance().add_endRequest(defineValidationFunction);", true); } }
Utils.js
function defineValidationFunction() { var ValidatorConvert = function (op, dataType, val) { //>>Consider everything as valid (client side) return op.toString(); } }
With that in place, my code works for all pages that uses the MasterPage. The code will constantly overwrite the validation function with mine. There's a little bit of overhead but I couldn't figure out another way.
相关问答
更多-
您并不完全了解Ajax和UpdatePanel的工作方式。 实际上,UpdatePanel,从客户端,通过发出一个post请求从服务器数据询问,然后等待获取它们,之后获取数据是更新客户端。 浏览器必须发出获取数据的请求 - 服务器无法向浏览器发送任何数据,而第一个浏览器请求它们。 命令updatePanel.Update(); 有意思通知UpdatePanel有一个更新,在帖子后面的代码后面 - 并且不像您想的那样工作,不是因为您调用它而不是将数据发送到UpdatePanel。 即使您在帖子之后进行了类似的 ...
-
在您的JavaScript event handler ,如果输入正确,则变量bool仅初始化。 因此,如果输入不正确,函数将返回undefined而不是false 。 但是,如果在click event handler返回false ,则click event handler按钮的回发仅会被抑制。 此外,您必须确保没有任何JavaScript错误,因为它们也可能导致回发。 因此,要解决您的问题,只需将validate函数的开头更改为: function validate() { var bool ...
-
感谢Yuriy的意见,我能够提出一个解决方案。 基本上,我创建的代码将在页面首次加载时定义我的函数。 此外,我注册了我的自定义函数,以在每次ajax请求后重新定义我的函数。 鉴于我将此代码放在MasterPage上,我能够使其在所有应用程序中运行。 这是代码: MasterPage.aspx是一个简单的Html页面,其ContentPlaceHolders和ScriptManager位于表单标签的正下方。 另外,我必须在页面顶部(head标签)添加对“Utils.js”的引用。 MasterPage.asp ...
-
ASP.NET在updatepanel中动态添加了下拉回发(ASP.NET dynamically added dropdown postback in updatepanel)[2021-12-01]
放 UpdatePanel1.Triggers.Add(new AsyncPostBackTrigger() { ControlID = "ddl1" }); 将下拉列表添加到控制面板后(在Panel1.Controls.Add(ddl);行之后) Put UpdatePanel1.Triggers.Add(new AsyncPostBackTrigger() { ControlID = "ddl1" }); after you add the dropdown to the control panel ( ... -
我在ScriptManager.RegisterStartupScript中输出的脚本中存在错误。 这会导致运行时错误,因为当