2012-06-16 36 views
-2

为什么会这样?警告:shuffle()期望参数1是数组

Warning: shuffle() expects parameter 1 to be array, resource given in /home/u801961841/public_html/img.php on line 12 

真正PHP代码:

<?php 
require_once 'masterfile.php'; 
    $text3 = wordwrap($t[0], 31, "\n", true); 
    $box = @ImageTTFBBox(23,0,'/home/u801961841/public_html/nama.TTF',$user[name]); 
    $textwidth = abs($box[4] - $box[0]); 
    $x_finalpos = 255-($textwidth/2); 
    $image = imagecreatefromjpeg('img_empty.jpg'); 
    $image = imagecreatefromjpeg('img_empty1.jpg'); 
    $image = imagecreatefromjpeg('img_empty2.jpg'); 
    $image = imagecreatefromjpeg('img_empty3.jpg'); 
    $image = imagecreatefromjpeg('img_empty4.jpg'); 
shuffle($image); 
    $font_color = ImageColorAllocate($image, 0, 0, 0); 

请帮我解决这个问题:(

+2

错误信息似乎很清楚:X – Esailija

回答

6

你没有设置$image作为数组操作:

$image[] = imagecreatefromjpeg('img_empty.jpg'); 
$image[] = imagecreatefromjpeg('img_empty1.jpg'); 
$image[] = imagecreatefromjpeg('img_empty2.jpg'); 
$image[] = imagecreatefromjpeg('img_empty3.jpg'); 
$image[] = imagecreatefromjpeg('img_empty4.jpg'); 
+0

但他却成了这么好: –

+0

但他却成了这么好: 警告:imagecolorallocate():提供的参数不是在/ home/u801961841 /的public_html /有效的图像资源img.php on line 13 Warning:imagettftext()期望参数1是资源,在第14行给出的/home/u801961841/public_html/img.php中的数组 警告:imagettftext()期望参数1是资源,数组在/ home/u801961841/public_html/img.php在线15 –

2

如果我理解你的权利,你需要采取随机图片?

$images = array(
'img_empty.jpg', 
'img_empty1.jpg', 
'img_empty2.jpg', 
'img_empty3.jpg', 
'img_empty4.jpg'  
); 

$image = imagecreatefromjpeg($images[array_rand($images)]); 
$font_color = ImageColorAllocate($image, 0, 0, 0); 

这样你只需要分配资源到需要的图片。

+0

谢谢;)希望你是丰富和成功的! –

+0

@Aurimas不要忘记,这是作为接受的答案嫖娼。 – mario

相关问题