We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40683
    • 4 Posts
    phpThumbOf 1.4.0 outputs the same preview from the different images which have the same base names.

    I have some images which are placed to:
    assets/images/1/11.jpg
    assets/images/1/21.jpg
    assets/images/1/31.jpg

    assets/images/2/11.jpg
    assets/images/2/21.jpg
    assets/images/2/31.jpg

    I output images using snipet by passing arrays of images:
    <?php
    $listPict = $modx->getOption('listPict', $scriptProperties, NULL);
    
    if (empty($listPict))
    {
      return "";
    }
    else
    {
      $output = "";
      foreach (explode(",", $listPict) as $image)
      {
        if (!empty($image))
        {
          $output .= "<div class=\"feedback_image\"><a rel=\"lightbox_group\" title=\"\" href=/" . $image. "><img alt=\"\" src=\"" . $modx->runSnippet('phpthumbof', array("input" => $image, "options" => "w=160&h=300&zc=1")) . "\"></a></div>";
        }
      }
      return $output;
    }
    


    The result is: I have 2 group of images wiht the same preview.

    Could anyone suggest something?

    This question has been answered by ivan_sobaka. See the first response.

    • discuss.answer
      • 40683
      • 4 Posts
      I found out the problem. It is a bug in the
      \core\components\phpthumbof\model\phpthumbof\phpthumbof.class.php


      I replaced string: $this->cacheFilename = basename($inputSanitized) to $this->cacheFilename = str_replace(array(':','/'),'_',$inputSanitized);
      public function getCacheFilename() {
              /* either hash the filename */
              if ($this->modx->context->getOption('phpthumbof.hash_thumbnail_names',false,$this->config)) {
                  $inputSanitized = str_replace(array(':','/'),'_',$this->input);
                  $this->cacheFilename = md5($inputSanitized);
                  $this->cacheFilename .= '.'.md5(serialize($this->options));
                  $this->cacheFilename .= '.' . (!empty($this->options['f']) ? $this->options['f'] : 'png');
              } else { /* or attempt to preserve the filename */
                  $inputSanitized = str_replace(array('http://','https://','ftp://','sftp://'),'',$this->input);
                  $inputSanitized = str_replace(array(':'),'_',$inputSanitized);
                  /*
      It is a bug. cacheFilename shuldn't be the same as just 'basename'
      $this->cacheFilename = basename($inputSanitized);
      */
      			$this->cacheFilename = str_replace(array(':','/'),'_',$inputSanitized);
                  if ($this->modx->context->getOption('phpthumbof.postfix_property_hash',true,$this->config)) {
                      if (!empty($this->options['f'])) { /* get rid of the middle extension and put it at the end */
                          $length = strlen($this->cacheFilename);
                          $extLength = strlen($this->options['f']);
                          $cut = $length-$extLength-1;
                          if (strlen($this->cacheFilename) > $cut) {
                              $this->cacheFilename = substr($this->cacheFilename,0,$cut);
                          }
                      }
                      $this->cacheFilename .= '.'.md5(serialize($this->options)).$this->modx->resource->get('id');
                      $this->cacheFilename .= '.' . (!empty($this->options['f']) ? $this->options['f'] : 'png');
                  }
              }
              $this->cacheKey = $this->config['cachePath'].$this->cacheFilename;
              return $this->cacheKey;
          }
      
        • 27223
        • 2 Posts
        Wow this Bug is not solved after 11 months:
        http://tracker.modx.com/issues/8358

        Thanks to ivan_sobaka, this post saved me a lot of time
        • Quote from: silence_le at Jul 10, 2013, 04:12 PM
          Wow this Bug is not solved after 11 months:
          http://tracker.modx.com/issues/8358

          Yes, there are a bunch of open issues and pull requests on GitHub which haven't gotten a response for a year now.
          You might take a look at my fork of phpThumbOf, unimaginatively called pThumb. It fixes this bug and most of the other open issues, plus adds a few new features. It uses the same namespace and snippet name as phpThumbOf, so you just uninstall phpThumbOf and install pThumb.
            Extras :: pThumbResizerimageSlimsetPlaceholders