Jump to content
Sign in to follow this  
katilina

[Решено] Функция imagecreatefromjpeg возвращает пустое значение

Recommended Posts

Уважаемые разработчики, помогите решить проблему. В контроллере модуля Обратной связи в пользовательской части для капчи определена функция

function captcha() {
		
		$rand = time() + (mt_rand(0, time()));
		$ra = mt_rand(1, 10);
		$random = substr($rand, 1, $ra);
		$code = substr(hexdec(md5(date("F j").$random)), 2, 6);
		$this->session->data['pin'][$this->request->get['captcha_id']] = $code;
		
		
		$image = imagecreatefromjpeg(DIR_SYSTEM.'captcha/captcha.jpg');
		$color = imagecolorallocate($image, rand(50, 150), rand(50, 100), rand(50, 150));
		
		imagettftext($image, 14, rand(-3, 3), rand(5, 15), 18, $color, DIR_SYSTEM."captcha/x.ttf", $code);
	
		ob_start();
			imagejpeg($image, "", 100);
			imagedestroy($image);
		$data = base64_encode(ob_get_clean());
		echo $data;
		

	}

На денвере работает прекрасно, на сервере ошибка imagejpeg(): Filename cannot be empty

 

Как понимаю, функция не успевает создать картинку.

В интернете нашла вот такое решение http://www.php.su/imagecreatefromjpeg

Но то ли я его реализую неправильно, то ли ошибка в другом месте. Не могу разобраться.

 

Share this post


Link to post
Share on other sites

http://php.net/manual/ru/function.imagejpeg.php

...
// Пропускаем параметр filename, используя NULL, а затем устанавливаем качество в 75%
imagejpeg($im, NULL, 75);
...

Share this post


Link to post
Share on other sites

Спасибо огромное, теперь работает.  С наступающим Новым годом!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.