PHP 中的图像转换

发布于 2025-01-16 20:17:19 字数 1552 浏览 6 评论 0原文

我有一本书,其中有一个从用户提供的随机图片创建全新图片的示例,我认为该示例有问题,至少我不能使用它。浏览器中PHP返回的错误代码:

Fatal error: Uncaught Error: Call to undefined function imagecreatefromstring() in C:\xampp\htdocs\kepkonvertalas.php:13 Stack trace: #0 {main} thrown in C:\xampp\htdocs\kepkonvertalas.php on line 13

HTML形式:

<form action="kepkonvertalas.php" method="post" enctype="multipart/form-data">
   <input type="file" name="kep"><br>
   <input type="submit" value="kuldes">
</form>

PHP部分:

<?php
 $fajl = $_FILES['kep']['tmp_name'];
 $kep = file_get_contents($fajl);
 $forraskep = imagecreatefromstring($kep);
 $szelesseg = imageSX($forraskep);
 $magassag = imageSY($forraskep);
 $ujmagassag = 400;
 $ujszelesseg = $ujmagassag*($szelesseg/$magassag);
 $ujkep = imagecreatetruecolor($ujszelesseg, $ujmagassag);
 $eredmeny = imagecopyresampled($ujkep, $forraskep, 0, 0, 0, 0, $ujszelesseg, $ujmagassag, $szelesseg, $magassag);
 imagejpeg($ujkep, "ujkep.jpg");
?>
<img src="ujkep.jpg" alt="">`

可疑的是,这个扩展没有实现到我的php.ini中,但我找不到任何证据对于它,要么解决问题。感谢您的帮助!

我尝试从 URL 实现图片,并对其进行转换,这意味着我删除了

$fajl = $_FILES['kep']['tmp_name'];
$kep = file_get_contents($fajl);`

并且我使用图片 URL 创建了一个变量,然后在 $forraskep = imagecreatefromstring($kep);

我只是这样改变:

$forraskep = imagecreatefromstring(file_get_contents($src);

那么下一个问题是,>$forraskep 变量未定义。

我期望输出具有给定参数大小的图片。

I have a book where is a sample for creating a whole new picture, from a random picture given by the user, and I think there is something wrong in the example, at least I can't use it. The error code gave back by the PHP in the browser:

Fatal error: Uncaught Error: Call to undefined function imagecreatefromstring() in C:\xampp\htdocs\kepkonvertalas.php:13 Stack trace: #0 {main} thrown in C:\xampp\htdocs\kepkonvertalas.php on line 13

The HTML form:

<form action="kepkonvertalas.php" method="post" enctype="multipart/form-data">
   <input type="file" name="kep"><br>
   <input type="submit" value="kuldes">
</form>

The PHP part:

<?php
 $fajl = $_FILES['kep']['tmp_name'];
 $kep = file_get_contents($fajl);
 $forraskep = imagecreatefromstring($kep);
 $szelesseg = imageSX($forraskep);
 $magassag = imageSY($forraskep);
 $ujmagassag = 400;
 $ujszelesseg = $ujmagassag*($szelesseg/$magassag);
 $ujkep = imagecreatetruecolor($ujszelesseg, $ujmagassag);
 $eredmeny = imagecopyresampled($ujkep, $forraskep, 0, 0, 0, 0, $ujszelesseg, $ujmagassag, $szelesseg, $magassag);
 imagejpeg($ujkep, "ujkep.jpg");
?>
<img src="ujkep.jpg" alt="">`

What is suspect, is that this extension is not implemented into my php.ini, but I cant find any proof for it, either solve the problem. Thanks for the help!

I tried to implement a picture from an URL, and do the conversion on that, which means I deleted the

$fajl = $_FILES['kep']['tmp_name'];
$kep = file_get_contents($fajl);`

And I've made a variable with a picture URL, and in the
$forraskep = imagecreatefromstring($kep);

I just changed like this:

$forraskep = imagecreatefromstring(file_get_contents($src);

Well the next problem was, that the $forraskep variable was not defined.

I expect an output where I have the picture with the size of the given parameters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡忘如思 2025-01-23 20:17:19

解决方案实际上有点简单:

  1. 打开 php.ini
  2. 搜索“extension=gd”
  3. 删除分号
  4. 重新启动 apache 服务器

The solution was actually kinda easy:

  1. open php.ini
  2. search for "extension=gd"
  3. delete the semicolon
  4. restart apache server
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文