Imagemagick thumbnail generation with php - using -crop

前端 未结 2 1160
旧时难觅i
旧时难觅i 2021-01-29 04:41

Long ago I created a small library for resizing images using imagemagick through system(...) because I did not feel that the build-in imagemagick functions for PHP

相关标签:
2条回答
  • 2021-01-29 05:23

    I tell one suggestion you can try it,

    I saw the Image link I think the conditions are not checked correctly.

    you have checked condition [(width/height) > (maxWidth/maxHeight)] Instead of check

    if(width == height) { } elseif(width > height) { } else(width < height){ }

    Check this condition and according to this condition crop the image and resize.

    Thank you

    0 讨论(0)
  • 2021-01-29 05:26

    The solution was the following:

        if ($width/$height > $this->maxWidth/$this->maxHeight) {
          // then resize to the new height...
                    $command .= ' -resize "x'.$this->maxHeight.'"';
    
                    // ... and get the middle part of the new image
                    // what is the resized width?
                    $resized_w = ($this->maxHeight/$height) * $width;
    
                    // crop
                    $command .= ' -crop "'.$this->maxWidth.'x'.$this->maxHeight.'+'.round(($resized_w - $this->maxWidth)/2).'+0" +repage';
                } else {
                  $command .= ' -resize "' . $this->maxWidth . 'x"';
                  $resized_h = ($this->maxWidth/$width) * $height;
    
                    // crop
                    $command .= ' -crop "'.$this->maxWidth.'x'.$this->maxHeight.
                                 '+0+'.round(($resized_h - $this->maxHeight)/2).'" +repage';
                }
    
    0 讨论(0)
提交回复
热议问题