CodeIgniter 图像操作。脚本混淆文件名

发布于 2024-09-11 19:22:32 字数 1266 浏览 1 评论 0原文

这是来自使用其图像处理库的 CodeIgniter 应用程序。

$photos 包含相对照片路径的数组。此脚本应调整原始尺寸并创建中号 (_m) 和小号 (_s) 尺寸。

当我只向脚本发送一张照片时,一切都很好。

当我发送第二个图像时,事情就搞砸了 - 第一个图像工作正常,但随后:

- 原始的第二个图像根本没有调整大小(应调整为 800 宽/高)
- “原始”第二个图像图像尺寸 (800x800) 被命名为带有第一个图像文件名的小图像。

foreach($photos as $photo) {
  $config['image_library'] = 'gd2';
  $config['source_image']  = $photo;
  $config['maintain_ratio'] = TRUE;

  $photoparts = pathinfo($photo);

  // Resize Original
  $config['width']   = 800;
  $config['height']  = 800;
  $this->image_lib->initialize($config);
  $this->image_lib->resize();

  // Medium Size
  $config['width']   = 500;
  $config['height']  = 500;
  $config['new_image'] = $photoparts['dirname'].'/'.$photoparts['filename'].'_m.'.$photoparts['extension'];
  $this->image_lib->initialize($config);
  $this->image_lib->resize();

  // Small Size
  $config['width']   = 200;
  $config['height']  = 200;
  $config['new_image'] = $photoparts['dirname'].'/'.$photoparts['filename'].'_s.'.$photoparts['extension'];
  $this->image_lib->initialize($config);
  $this->image_lib->resize();
}

我一生都无法弄清楚为什么文件名会混淆。我唯一能想到的是,我是在本地服务器上完成这一切,所以也许它运行得太快,以至于脚本超出了自身的速度?但我怀疑情况确实如此。

This is from a CodeIgniter application that uses its image manipulation library.

$photos contains an array of relative photo paths. This script should resize the original and also create a medium (_m) and small (_s) size.

When I only send one photo to the script, everything works great.

When I send a second, things get screwed up - the first image works fine, but then:

-The original second image isn't resized at all (should be resized to 800 wide/high)
-The "original" second image size (800x800) is named as a small image with the first image's file name.

foreach($photos as $photo) {
  $config['image_library'] = 'gd2';
  $config['source_image']  = $photo;
  $config['maintain_ratio'] = TRUE;

  $photoparts = pathinfo($photo);

  // Resize Original
  $config['width']   = 800;
  $config['height']  = 800;
  $this->image_lib->initialize($config);
  $this->image_lib->resize();

  // Medium Size
  $config['width']   = 500;
  $config['height']  = 500;
  $config['new_image'] = $photoparts['dirname'].'/'.$photoparts['filename'].'_m.'.$photoparts['extension'];
  $this->image_lib->initialize($config);
  $this->image_lib->resize();

  // Small Size
  $config['width']   = 200;
  $config['height']  = 200;
  $config['new_image'] = $photoparts['dirname'].'/'.$photoparts['filename'].'_s.'.$photoparts['extension'];
  $this->image_lib->initialize($config);
  $this->image_lib->resize();
}

I can't figure out for the life of me why the file names are getting mixed up. The only thing I can think of is that I'm doing this all on a local server, so maybe it's running so fast that the script gets ahead of itself? I doubt that's the case, though.

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

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

发布评论

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

评论(1

遥远的她 2024-09-18 19:22:34

我终于想通了 - 我想我是在其他人产生问题之前修改了原始源图像,所以当我将该部分移到最后时,一切正常。

I finally figured it out - I guess the fact that I was modifying the original source image before the others was creating problems, so when I moved that part to the end, everything works fine.

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