Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 字符串文件路径内存替代(文件路径的替代方式)_Php_Memory_Path_Filepath_Iptc - Fatal编程技术网

Php 字符串文件路径内存替代(文件路径的替代方式)

Php 字符串文件路径内存替代(文件路径的替代方式),php,memory,path,filepath,iptc,Php,Memory,Path,Filepath,Iptc,我有一个资源对象(图像),它是经过大量处理后从ImageCreateTureColor创建的 $image=imageCreateTureColor($dst_宽度,$dst_高度) 最后一步是将iptc标签添加到图像中 为了添加iptc标记,php具有本机函数,称为iptcembed iptcembed ( string $iptcdata , string $jpeg_file_name [, int $spool ] ); 问题是:我将图像存储为资源对象。但iptcembed需要图像作为

我有一个资源对象(图像),它是经过大量处理后从ImageCreateTureColor创建的

$image=imageCreateTureColor($dst_宽度,$dst_高度)

最后一步是将iptc标签添加到图像中

为了添加iptc标记,php具有本机函数,称为iptcembed

iptcembed ( string $iptcdata , string $jpeg_file_name [, int $spool ] );
问题是:我将图像存储为资源对象。但iptcembed需要图像作为文件路径字符串$jpeg\u file\u name

对于每个图像,我应该保存图像并从iptc标签的iptcembed加载它

这是一个很大的性能问题。还有肮脏的代码

我认为php包装器可以解决这个问题,但我知道它们不是路径。它们只是参考资料。以下代码对我不起作用

    $data = null;
    ob_start();
    imagejpeg($this->image['src_image'], null, $compression);
    $data = ob_get_contents();
    ob_end_clean();

    $img = fopen("php://temp", 'wb+');
    fwrite($img, $data);
    fclose($img);

    $content = iptcembed('', "php://temp");
问题是:有没有什么技巧可以让我从内存中找到这个imagepath/或者更好的方法来实现它?

这里也有同样的问题:)

我在数据库中存储了高分辨率的“主”jpeg图像流。我必须为下载请求提供随机调整大小、裁剪和压缩参数。最后一步是向创建的临时映像添加一些元数据

我正在使用PHP5.6(Windows7)和7.2(Ubuntu18)。到目前为止,我最快的解决方案是一个小型专用ramdisk。在Ubuntu上,我只是创建并安装了一个tmpfs文件系统:

$ sudo bash
# mkdir -p /media/ramdisk
# chmod 1777 /media/ramdisk
# mount -t tmpfs -o size=256M tmpfs /media/ramdisk
# grep /media/ramdisk /etc/mtab | tee -a /etc/fstab
tmpfs /media/ramdisk tmpfs rw,relatime,size=262144k 0 0
# ^D
$ df -m /media/ramdisk
Filesystem     1M-blocks  Used Available Use% Mounted on
tmpfs                256     0       256   0% /media/ramdisk
$
在Windows上,我从SoftPerfect安装了免费RAM磁盘应用程序(可在此处获得:)


当然,这与您的几乎相同。

我猜动态函数不可用的主要原因是这样一个函数会立即在jpeg流中显示GD库自己的注释:“创建者:GD jpeg v1.0(使用IJG jpeg v90),质量=100”。
C:\>dir k:
 Volume in drive K is Ram Disk
 Volume Serial Number is 5566-7788

 Directory of K:\

2018-11-14  19:18    <DIR>          cache
2018-11-14  19:18    <DIR>          temp
               0 File(s)              0 bytes
               2 Dir(s)     117 518 336 bytes free
$raw = ...; // obtain untagged jpeg stream //
$temp = '/path/to/file/on/ram/disk';
file_put_contents($temp, $raw);
$meta = ...; // set the metadata as needed //
$raw = iptcembed($meta, $temp); // reload tagged image stream //
unlink($temp); // don't forget to clean up //