错误: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?

2023-02-03 19:02

满意答案

在您的情况下,您必须使用imagecreatefrompng来获取文件的资源。 请尝试以下方法:

$barcode = imagecreatefrompng('barcode_test.png');
$image = ImageCreate($width, $height);
ImageCopyMerge($image,$barcode,0,0,0,0,400,100,0);

如果您正在使用其他文件类型,则必须根据扩展名选择以下函数之一: imagecreatefromgd2imagecreatefromgd2partimagecreatefromgdimagecreatefromgifimagecreatefromjpegimagecreatefrompngimagecreatefromstringimagecreatefromwbmpimagecreatefromwebpimagecreatefromxbmimagecreatefromxpm


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

相关问答

更多

错误:imagecopymerge()期望参数2是资源(Error: imagecopymerge() expects parameter 2 to be resource)

在您的情况下,您必须使用imagecreatefrompng来获取文件的资源。 请尝试以下方法: $barcode = imagecreatefrompng('barcode_test.png'); $image = ImageCreate($width, $height); ImageCopyMerge($image,$barcode,0,0,0,0,400,100,0); 如果您正在使用其他文件类型,则必须根据扩展名选择以下函数之一: imagecreatefromgd2 , imagecr...

如何解决这个错误“mysql_fetch_assoc()期望参数1是资源,布尔值在”?(How to fix this error “mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in”? [duplicate])

$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_fetc...

ftp_get()期望参数2是有效的路径,给定资源(ftp_get() expects parameter 2 to be a valid path, resource given)

因为您使用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: ht...

mysql_fetch_array()期望参数1是资源错误[重复](mysql_fetch_array() expects parameter 1 to be resource error [duplicate])

您的查询以某种方式失败,并返回一个布尔值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 w...

警告:fgetcsv()期望参数1是资源,布尔值在C:(Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:)

在尝试使用结果之前,您需要测试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($...

fclose()期望参数1是eval()中给出的资源,数组(fclose() expects parameter 1 to be resource, array given in eval())

fclose()期望文件句柄,你传递文件内容。 你想要这样的东西: $handle = fopen("https://www.example.com/tock.txt", "r"); $csv = fgetcsv($handle); fclose($handle); 注意: 您通常不需要调用fclose() ,因为它会在脚本末尾隐式触发。 如果文件包含多行,则需要多次调用fgetcsv() 。 此外,应尽可能避免使用eval() 。 它通常会引入重大的安全问题。 fclose() expects...

sqlsrv_num_rows()期望参数1是资源(sqlsrv_num_rows() expects parameter 1 to be resource)

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....

imagecopymerge没有响应(imagecopymerge not responding)

这样做...... <?php $unframedPhoto= imagecreatefromjpeg('unframedPhoto.jpg'); $frame = imagecreatefromjpeg('frame.jpg'); imagecopymerge($frame, $unframedPhoto, 200, 200, 0, 0, 800, 800,0); header('Content-Type: image/jpeg'); imagejpeg($frame); imagedest...

警告:imagecolorallocate()期望参数1是资源,给定布尔值(Warning: imagecolorallocate() expects parameter 1 to be resource, boolean given)

我已经通过安装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 th...

warning feof()期望参数1是资源(warning feof() expects parameter 1 to be resource)

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:...

相关文章

更多

【第四章】 资源 之 4.2 内置Resource实现 ——跟我学spring3

4.2 内置Resource实现4.2.1 ByteArrayResource ByteArray ...

【第四章】 资源 之 4.4 Resource通配符路径 ——跟我学spring3

前面介绍的资源路径都是非常简单的一个路径匹配一个资源,Spring还提供了一种更强大的Ant模式通配符 ...

【第四章】 资源 之 4.3 访问Resource ——跟我学spring3

Spring提供了一个适用于所有环境的DefaultResourceLoader实现,可以返回Clas ...

移动MM failed to find resource file{mmiap.xml}

原地址:http://blog.csdn.net/alking_sun/article/details ...

使用mybatis执行sql的时候为什么会出现Parameter index out of range (1 > number of parameters, which is 0)?

写like语句的时候 一般都会写成 like '% %' 在mybatis里面写就是应该是 ...

freemarker页面get型参数转码问题

系统为:tomcat, Spring+Spring MVC+freemarker 由于tomcat上 ...

【第四章】 资源 之 4.1 基础知识 ——跟我学spring3

Spring 提供一个Resource接口来统一这些底层资源一致的访问,而且提供了一些便利的接口,从而 ...

表单提交后报406错误

表单提交后报HTTP Status 406错误: type:Status report messa ...

Oracle ORA-04031 错误 说明

在 老熊 的Blog上看到他们写的有关ORA-04031的文章,转到blog。 老熊的Blog: ht ...

最新问答

更多

绝地求生、荒野行动、香肠派对 哪个更好玩???(都是吃鸡类游戏)

PC上的绝地求生,是最早也是最火的大逃杀游戏。 荒野行动是网易抄袭蓝洞绝地求生制作的手游。相似度90%,还有他一起出的终结折2,这2款正在被蓝洞告,打官司呢。 手游上的绝地求生有2部都是蓝洞授权(收钱)给腾讯开发的正版ID手游。所以跟PC上做的一模一样,蓝洞也没话说。 加上吃鸡国服也是腾讯独家代理,所以根本没有什么可说的。只要这个类型的 过于相似的,腾讯都可以借蓝洞之手起诉。打压同行是国内BAT最爱干的事嘛! 香肠派对画风虽然不一样,但核心玩法还是跟人家正版的一样的,同样也是没有被授权的。 98

如何在jQuery集合中选择第n个jQuery对象?(How to select the nth jQuery object in a jQuery collection?)

你可以使用eq : var rootElement = $('.grid').find('.box').eq(0); rootElement.find('.a'); /* Use chaining to do more work */ You can use eq: var rootElement = $('.grid').find('.box').eq(0); rootElement.find('.a'); /* Use chaining to do more work */

ASP NET使用jQuery和AJAX上传图像(ASP NET upload image with jQuery and AJAX)

您可以自己手动设置FormData键和值。 Upload 创建FormData并设置新的键/值 $("#btnUpload").on("click", function(e) { e.preventDefault(); var file = $("#imguploader").get(0).file

SQL Server XML查询中包含名称空间的位置(SQL Server XML query with namespaces in the where exist)

您可能希望使用#temp.identXml.query而不是#temp.identXml.query 。 您可以在这里阅读更多相关信息SQL Server XML exists() 我相信你也可以像这样使用它 Select #temp.identXml.value('(/*:PersonIdentity/*:MasterIndexes/*:PersonIndex/*:SourceIndex)[1]','varchar(100)') as Ident ,#temp.identXml.value(

宁夏银川永宁县望远镇哪里有修mp5的?

胜利街有家电维修,电脑城,银川商场多得很…

我想用更新的日期标记所有更新的行(I would like to mark all updated rows with the date that they have been updated)

您可以使用更新后触发的触发器来执行此操作。 给出如下表: create table your_table (id int primary key, val int, last_update datetime) 每当您更新表中的内容时,此触发器将设置last_update值。 CREATE TRIGGER trigger_name ON your_table AFTER UPDATE AS BEGIN UPDATE your_table SET your_ta

郑州会计培训班

招生的,至于时间吗,就看你自己的时间段了,你可以致电0371-63300220.他们会帮你选择一下的。离你最近,最专业的培训班。

如何定位数组中的负数,并得到所有正数的总和?(How to target e negative number from an array, and get the sum of all positive numbers?)

只需创建一个条件来检查它是正数还是负数,然后定义一个空的数组negatives ,如果数字是负数,则将其推到负数组中,如果是正数,则将其添加到sum变量中,请查看下面的工作示例。 function SummPositive( numbers ) { var negatives = []; var sum = 0; for(var i = 0; i < numbers.length; i++) { if(numbers[i] < 0) { negati

在响应图像上叠加网格(Overlay grid on responsive image)

使用两个linear-gradient s,我们可以创建两个简单的线条,然后每隔n%重复一次background-size 。 它看起来像这样: background: linear-gradient(to bottom, #000 2px, transparent 2px), linear-gradient(to right, #000 2px, transparent 2px); background-size: 10%; 两个渐变创建两条相交的线,长度为百分比,如下所示: 使用默认的b

无法让POST在Azure网站上运行(Could not get POST to work on Azure Website)

最后我找到了答案......我不得不删除尾随的斜线! 我使用了“ https://example.com/api/messages/ ”,这将自动产生GET,无论我使用PostAsync还是PostAsJsonAsync。 使用“ https://example.com/api/messages”,GET和POST似乎都运行良好! Finally I've found the answer.... I had to remove the trailing slash! I've used "ht