错误:imagecopymerge()期望参数2是资源(Error: imagecopymerge() expects parameter 2 to be resource)
尝试在PHP中将图像设置为变量时出错:
$barcode= 'barcode_test.png'; $image = ImageCreate($width, $height); ImageCopyMerge($image,$barcode,0,0,0,0,400,100,0);
PHP警告:imagecopymerge()期望参数2是资源,给定字符串
如何让
$barcode
成为资源,而不是字符串?Getting an error trying to set an image as a variable in PHP:
$barcode= 'barcode_test.png'; $image = ImageCreate($width, $height); ImageCopyMerge($image,$barcode,0,0,0,0,400,100,0);
PHP Warning: imagecopymerge() expects parameter 2 to be resource, string given
How do I make
$barcode
a resource, not a string?
最满意答案
在您的情况下,您必须使用
imagecreatefrompng
来获取文件的资源。 请尝试以下方法:$barcode = imagecreatefrompng('barcode_test.png'); $image = ImageCreate($width, $height); ImageCopyMerge($image,$barcode,0,0,0,0,400,100,0);
如果您正在使用其他文件类型,则必须根据扩展名选择以下函数之一:
imagecreatefromgd2
,imagecreatefromgd2part
,imagecreatefromgd
,imagecreatefromgif
,imagecreatefromjpeg
,imagecreatefrompng
,imagecreatefromstring
,imagecreatefromwbmp
,imagecreatefromwebp
,imagecreatefromxbm
,imagecreatefromxpm
In your case you have to use
imagecreatefrompng
to get a resource of the file. Try the following:$barcode = imagecreatefrompng('barcode_test.png'); $image = ImageCreate($width, $height); ImageCopyMerge($image,$barcode,0,0,0,0,400,100,0);
If you are using another file type you have to choose one of the following function depending on the extension:
imagecreatefromgd2
,imagecreatefromgd2part
,imagecreatefromgd
,imagecreatefromgif
,imagecreatefromjpeg
,imagecreatefrompng
,imagecreatefromstring
,imagecreatefromwbmp
,imagecreatefromwebp
,imagecreatefromxbm
,imagecreatefromxpm
相关问答
更多-
在您的情况下,您必须使用imagecreatefrompng来获取文件的资源。 请尝试以下方法: $barcode = imagecreatefrompng('barcode_test.png'); $image = ImageCreate($width, $height); ImageCopyMerge($image,$barcode,0,0,0,0,400,100,0); 如果您正在使用其他文件类型,则必须根据扩展名选择以下函数之一: imagecreatefromgd2 , imagecreatef ...
-
$query在while之前和while ...将变量的名称更改为$query2 ,例如: $hoje = strtotime(date("d-m-Y")); $db = new DBConfig(); $db -> config(); $db->conn(); $query = mysql_query("SELECT * FROM products WHERE auto_pub = ".$hoje) or die(mysql_error()); while($res = mysql_fetch_ass ...
-
ftp_get()期望参数2是有效的路径,给定资源(ftp_get() expects parameter 2 to be a valid path, resource given)[2022-08-19]
因为您使用ftp_fget的文档而不是ftp_get: http ://php.net/manual/en/function.ftp-get.php bool ftp_get ( resource $ftp_stream , string $local_file , string $remote_file , int $mode [, int $resumepos = 0 ] ) Because you use the doc of ftp_fget instead of ftp_get: http:// ... -
mysql_fetch_array()期望参数1是资源错误[重复](mysql_fetch_array() expects parameter 1 to be resource error [duplicate])[2022-08-18]
您的查询以某种方式失败,并返回一个布尔值FALSE而不是语句句柄。 添加此内容以找出原因: $query = mysql_query(...); if ($query === FALSE) { die(mysql_error()); } 永远不要假设数据库操作成功。 Your query has failed somehow, and returned a boolean FALSE instead of a statement handle. Add this to find out why: $ ... -
警告:fgetcsv()期望参数1是资源,布尔值在C:(Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:)[2022-07-08]
在尝试使用结果之前,您需要测试fopen是否成功: $handle = fopen($_FILES['filename']['tmp_name'], "r"); if ($handle) { // Use $handle } else { die("Unable to open file"); } You need to test whether fopen succeeded before you try to use the result: $handle = fopen($_FILE ... -
fclose()期望参数1是eval()中给出的资源,数组(fclose() expects parameter 1 to be resource, array given in eval())[2022-05-26]
fclose()期望文件句柄,你传递文件内容。 你想要这样的东西: $handle = fopen("https://www.example.com/tock.txt", "r"); $csv = fgetcsv($handle); fclose($handle); 注意: 您通常不需要调用fclose() ,因为它会在脚本末尾隐式触发。 如果文件包含多行,则需要多次调用fgetcsv() 。 此外,应尽可能避免使用eval() 。 它通常会引入重大的安全问题。 fclose() expects the ... -
sqlsrv_num_rows()期望参数1是资源 问题是$result是false,这是因为: $sql="SELECT * FROM Login WHERE Username=$myusername and Password=$mypassword"; 这里Username和Password是字符串,您要与字符串进行比较,您必须将值包装在' singe quotes中,如: $sql="SELECT * FROM Login WHERE Username='".$myusername."' an ...
-
这样做......我已经通过安装Attribute Wizard pro解决了这个问题,这是一个可以执行文件上传的prestashop模块,并且不使用有问题的.php文件。 我不得不购买该模块,但它更快,可能比花费我的时间进行调试更便宜,而不保证看到解决方案。 I've solved the problem by installing Attribute Wizard pro, a prestashop module that can do file uploads and that does not use the pro ...fopen失败并返回false。 false不是资源,因此是警告。 在将它作为类似资源的参数注入之前,你最好测试$ fp: if(($fp = fopen($file, "r"))) { [...] } fopen fails and returns false. false is not a resource, thus the warning. You'd better test $fp before injecting it as a resource-like argument: if(( ...
相关文章
更多- 【第四章】 资源 之 4.2 内置Resource实现 ——跟我学spring3
- 【第四章】 资源 之 4.4 Resource通配符路径 ——跟我学spring3
- 【第四章】 资源 之 4.3 访问Resource ——跟我学spring3
- 移动MM failed to find resource file{mmiap.xml}
- 使用mybatis执行sql的时候为什么会出现Parameter index out of range (1 > number of parameters, which is 0)?
- freemarker页面get型参数转码问题
- 【第四章】 资源 之 4.1 基础知识 ——跟我学spring3
- 表单提交后报406错误
- JasperReport报表填充参数
- Oracle ORA-04031 错误 说明
最新问答
更多- 在csproj中使用appdata环境变量(Use appdata environment variable in csproj)
- 从背景返回后,Skobbler Map崩溃(Skobbler Map crashes after returning from background)
- 如何保持对绑定服务的轮询?(How to keep polling a bound service?)
- ASP.NET单选按钮jQuery处理(ASP.NET radio button jQuery handling)
- Linux上的FORTRAN图形库(FORTRAN graphic library on Linux)
- 我们如何根据索引更新dynamodb表(不基于primary has和range key)(how can we update dynamodb table based on index(not based on primary has and range key))
- 功能包装避免重复(wrap of functions avoid duplicating)
- Android BroadcastReceiver和Activity.onPause()(Android BroadcastReceiver and Activity.onPause())
- 无法使用phonegap 2.4在Android上播放录音(unable to play audio recordings on android using phonegap 2.4)
- VS2015 + Resharper:不要使用C#6(VS2015 + Resharper: Don't use C#6)
- 大学电脑四级对初学者来说要多久能过
- 特殊字符删除?(Special characters remove?)
- Android视频教程现在网上的都比较零散呢?有些太坑爹了,感觉老师就是在想当然的讲
- 计算同一个表中不同行之间的差异[重复](Calculate delta's between different rows in same table [duplicate])
- Javaweb开发,技术路线是什么?该怎么写?
- JavaScript只在php代码中执行一次(JavaScript only executes once inside php code)
- 不兼容的字符编码:ASCII-8BIT和UTF-8(incompatible character encodings: ASCII-8BIT and UTF-8)
- Clojure(加载文件)给出错误(Clojure (load-file) gives an error)
- 为具有瞬态scala依赖性的spring-xd项目优化gradle(Optimize gradle for spring-xd project with transient scala dependency)
- 如何才能在Alpha测试模式下发布我的应用程序?(How can I publish my app in Alpha test mode only?)
- “没有为此目标安装系统映像”Xamarin AVD Manager(“No system images installed for this target” Xamarin AVD Manager)
- maven中的Scalatest:JUnit结果(Scalatest in maven: JUnit results)
- 使用android SDK将文件直接上传到存储桶中的文件夹(Upload a file directly to a folder in bucket using android SDK)
- 是否应将plists导入CoreData?(Should plists be imported to CoreData?)
- java.lang.reflect.InvocationTargetException JavaFX TableView(java.lang.reflect.InvocationTargetException JavaFX TableView)
- 根据唯一列值动态创建多个子集(Dynamically create multiple subsets based on unique column values)
- 使用CSS可以使HTML锚标签不可点击/可链接吗?(Is it possible to make an HTML anchor tag not clickable/linkable using CSS?)
- 嵌套的模板可能性(Nested template possibilities)
- 任何方式在iOS7 +上以编程方式打开蓝牙(Any way to turn on bluetooth programmatically on iOS7+)
- 如何为给定的SQL查询编写JPA查询(How I can write JPA query for given SQL query)