在将文件保存到新文件之前,如何从调整大小的文件中获取 md5?

发布于 2024-11-09 17:01:38 字数 417 浏览 6 评论 0原文

我正在调整 jpg 的大小,之后我想从中获取 md5,然后使用该 MD5 名称保存新图像。 代码如下所示:

$extension = 'jpg';
$img = imagecreatefromjpeg($source);

$tmp_img = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $newWidth, $newHeight, $plik[0], $plik[1]);

//$md5 - here i need to get md5...

imagejpeg($tmp_img, $md5.;'.'.$extension);
imagedestroy($img);

是否可以不先保存该 tmp 文件?

I'm doing resize on jpg, after that i would like to get md5 from it and then save new image with that MD5 name.
Code looks like that:

$extension = 'jpg';
$img = imagecreatefromjpeg($source);

$tmp_img = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $newWidth, $newHeight, $plik[0], $plik[1]);

//$md5 - here i need to get md5...

imagejpeg($tmp_img, $md5.;'.'.$extension);
imagedestroy($img);

Is it possible without saving that tmp file first?

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

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

发布评论

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

评论(1

苦笑流年记忆 2024-11-16 17:01:38

你能在顶部做吗...

$md5 = md5_file($source);

我还看到了一种技术,可以将图像文件流式传输到输出缓冲区并捕获它。

ob_start();
imagejpeg($tmp_img);
$data = ob_get_clean();

$md5 = md5($data);

然后您可以使用以下命令创建文件...

file_put_contents($md5 . '.' . $extension, $data);

Can you do at the top...

$md5 = md5_file($source);

I've also seen a technique where you stream the image file into an output buffer and capture that.

ob_start();
imagejpeg($tmp_img);
$data = ob_get_clean();

$md5 = md5($data);

You could then create your file with...

file_put_contents($md5 . '.' . $extension, $data);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文