• Register
    • Help

    striker  0 Items
    Currently Supporting
    • Home
    • News
    • Forum
    • Wiki
    • Support
      • Manage Subscriptions
      • FAQ
      • Support For
        • VaultWiki 4.x Series
        • VaultWiki.org Site
    • What's New?
    • Buy Now
    • Manual
    • 
    • Support
    • VaultWiki 4.x Series
    • Bug
    • Use XF imageManager for image manipulation tasks on Xenforo

    1. Welcome to VaultWiki.org, home of the wiki add-on for vBulletin and XenForo!

      VaultWiki allows your existing forum users to collaborate on creating and managing a site's content pages. VaultWiki is a fully-featured and fully-supported wiki solution for vBulletin and XenForo.

      The VaultWiki Team encourages you to join our community of forum administrators and check out VaultWiki for yourself.

    Issue: Use XF imageManager for image manipulation tasks on Xenforo

    • Issue Tools
      • View Changes
    1. issueid=6396 October 22, 2023 4:09 AM
      mazzly mazzly is offline
      Junior Member
      Use XF imageManager for image manipulation tasks on Xenforo

      When debugging https://www.vaultwiki.org/issues/6394/ I had a look at
      Code:
      src/addons/vw/vw/_core/model/image/format/vw.php
      and I see that there is a lot of code to handle resizing/orientation/cropping etc, especially with different GD / Imagick libraries...

      I would propose that for an XF installation, VW should use the existing ImageManager which already handles the heavy lifting of these things...

      Here is a sample code from an "attachment dimension resizing" add-on I wrote for our forum, feel free to reuse what you need from here:
      Code:
              $imageManager = \XF::app()->imageManager();
              $canResize = $imageManager->canResize($attachment->width, $attachment->height);
              if (!$canResize) {
                  return;
              }
              $limit = \XF::options()->attachmentMaxDimensions;
              $maxWidth = $limit['width'];
              $maxHeight = $limit['height'];
      
              $oldPath = $attachment->getAbstractedDataPath();
              $resizeTempFile = File::copyAbstractedPathToTempFile($oldPath);   // XF\Util\File;
              $image = $imageManager->imageFromFile($resizeTempFile);
              if (!$image) {
                  return;
              }
              $image->resize($maxWidth ?: $maxHeight, $maxHeight ?: null);
              $image->save($resizeTempFile);
      
              $db = $attachment->db();
              $db->beginTransaction();
              $file = new FileWrapper($resizeTempFile);  // XF\FileWrapper;
              $attachment->file_size = $file->getFileSize() ?: 0;
              $attachment->file_hash = md5_file($resizeTempFile);
              $attachment->width = $image->getWidth();
              $attachment->height = $image->getHeight();
              $attachment->save();
              try {
                  File::copyFileToAbstractedPath($resizeTempFile, $attachment->getAbstractedDataPath());
              } catch (\Exception $e) {
                  $db->rollback();
                  return;
              }
              $db->commit();
              File::deleteFromAbstractedPath($oldPath);
      The ImageManager also supports things like resizeAndCrop() as well as orientation changing if needed.
    Issue Details
    Issue Number 6396
    Issue Type Bug
    Project VaultWiki 4.x Series
    Category Attachments
    Status Working as Designed
    Priority 3 - Loss of Functionality
    Affected Version 4.1.7
    Fixed Version (none)
    Milestone (none)
    Software DependencyAny
    License TypePaid
    Users able to reproduce bug 0
    Users unable to reproduce bug 0
    Attachments 0
    Assigned Users (none)
    Tags (none)




    1. October 22, 2023 9:35 AM
      pegasus pegasus is offline
      VaultWiki Team
      I appreciate the thought, but when we rewrote our image formatter in 2017, it was to resolve a number of issues that XenForo's image manager still seems to ignore:
      - vulnerability to image decompression bombs (VWE-2017-3979). At the time this was being exploited on wikis in the wild. So yeah, can't switch to a library now that has no protection. Adequate protection requires manually stepping through the image binary data to make sure the data is safe before handing it off to Imagick or GD.
      - loss of copyright metadata after manipulating an image (more here). Again, adequate protection requires manually stepping through the image binary data to locate the existing metadata, then rewrite that data to the result image after manipulation.

      We reported these issues to both vBulletin and XenForo devs at the time. Since the issue was disclosed to them years ago, I see no issue discussing the issues publicly here now. But as before, we still recommend using VaultWiki's image management tools over any forum's built-in tools (for any purpose), due to these issues.
      Reply Reply  
    + Reply

    Assigned Users
    Loading Please Wait
    Tags
    Loading Please Wait
    • Contact Us
    • License Agreement
    • Privacy
    • Terms
    • Top
    All times are GMT -4. The time now is 11:04 PM.
    This site uses cookies to help personalize content, to tailor your experience, and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Learn more… Accept Remind me later
  • striker
    Powered by vBulletin® Version 4.2.5 Beta 2
    Copyright © 2025 vBulletin Solutions Inc. All rights reserved.
    Search Engine Optimisation provided by DragonByte SEO (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
    Copyright © 2008 - 2024 VaultWiki Team, Cracked Egg Studios, LLC.