CodeIgniter 图像操作。脚本混淆文件名
这是来自使用其图像处理库的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于想通了 - 我想我是在其他人产生问题之前修改了原始源图像,所以当我将该部分移到最后时,一切正常。
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.