Giter Site home page Giter Site logo

vips-image-editor's People

Contributors

joppuyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vips-image-editor's Issues

webp support planned?

Ho devs,

Is this Plugin still usable for latest wp versions?

Webp supported?

Thanks and

Best Regards

Crash in Library on image resize where one dimension is larger than the source

Using WEBP-Express and Vips Image Editor and Elementor.

I have an image that is 250x75

Elementor is trying to make a "thumbnail" of the image that is 250x250

In the file class-image-editor-vips.php

public function resize($max_w, $max_h, $crop = false)
 {

     if (($this->size['width'] == $max_w) && ($this->size['height'] == $max_h)) {
         return true;
     }
     try {
****************** This call will fail and return code not checked ***************
         $resized = $this->_resize($max_w, $max_h, $crop);
 		$this->image = $resized;
 		
         return true;

...


 protected function _resize($max_w, $max_h, $crop = false)
 {
 			
 ********************* this->size['width'] = 250, this->size['height'] = 75, max_x = 250, max_h = 250
     $dims = image_resize_dimensions($this->size['width'], $this->size['height'], $max_w, $max_h, $crop);
 	
     if (!$dims) {
        ******************* FAILURE DETECTED HERE because of image dimensions that image_resize_dimensions does not understand (see it's source) returns  error **************
         return new WP_Error('error_getting_dimensions', __('Could not calculate resized image dimensions'), $this->file);
     }
     list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;

     try {
         $resized = $this->image->crop($src_x, $src_y, $src_w, $src_h)->resize(max($dst_h / $src_h, $dst_w / $src_w));

         $this->update_size($dst_w, $dst_h);
         return $resized;
     } catch (Exception $exception) {
         return new WP_Error('crop_error', __('Failed to crop image'), $exception);
     }
 }


$this->image is now in an error state and further calls to
public function save($filename = null, $mime_type = null)

will crash

Sorry, I am not a PHP programmer here. C++ by trade.

Some thumbnail sizes not generated when using this plugin

Hi, thanks for writing this plugin. I have a huge performance improvement compared to ImageMagick. Unfortunately, when switching to VIPS on my production environment, I noticed that one particular size of thumbnail (650px x 433px - registered by the theme I'm using) is not generated from my pictures (which are admittedly quite big at 4000x2667). Bigger thumbnails are generated, but not this small one.

On my dev environment based on Homestead, it works though. Since the production and dev environment vary greatly (same php version though), my guess is that there is some kind of memory limit / timeout parameter at play. But I'm unable to find it. There is nothing in the php error logs.

How do you advise I debug this problem?

Thanks.

use `thumbnail`, if possible

Hello! I'm the libvips maintainer. This is very cool!

I had a couple of suggestions after looking through the code that could improve performance and drop memory use.

Use thumbnail, if you can

I would use thumbnail, if possible. It's much, much quicker than newFromBuffer and resize, especially for large reductions on JPG images, and will give higher quality results too, since it will automatically premultiply PNG alpha for you.

For example, I think this is roughly what you are doing at the moment:

#!/usr/bin/env php
<?php

require __DIR__ . '/vendor/autoload.php';

use Jcupitt\Vips;

# disable vips caching
Vips\Config::cacheSetMax(0);

for ($i = 0; $i < 100; $i++) {
  $contents = file_get_contents($argv[1]); 
  $image = Vips\Image::newFromBuffer($contents);
  $target_width = 256;
  $image = $image->resize($target_width / $image->width);
  $out = $image->writeToBuffer(".jpg");
}

If I run this on my laptop with a 6k x 4k JPG image, I see:

$ /usr/bin/time -f %M:%e ./try275.php ~/pics/theo.jpg
135168:18.91

ie. 135MB of memory, 19s of CPU. If I change it to be:

#!/usr/bin/env php
<?php

require __DIR__ . '/vendor/autoload.php';

use Jcupitt\Vips;

# disable libvips caching
Vips\Config::cacheSetMax(0);

for ($i = 0; $i < 100; $i++) {
  $image = Vips\Image::thumbnail($argv[1], 256);
  $out = $image->writeToBuffer(".jpg");
} 

I see:

$ /usr/bin/time -f %M:%e ./try276.php ~/pics/theo.jpg
51704:4.69

So 50MB of memory, under 5s of CPU.

You are cropping before resize, which you can't do with thumbnail. I would use thumbnail anyway, and crop afterwards using scaled down coordinates.

Disable caching

By default, libvips will cache the last 1,000 operations or so. This is usually great for performance, but you are not going to be repeatedly operating on the same image, so it is likely to bloat memory for no gain.

I would add:

Vips\Config::cacheSetMax(0);

To your startup code.

If I remove that line from try275.php (the non-thumbnail version above) I see:

$ /usr/bin/time -f %M:%e ./try275.php ~/pics/theo.jpg
213140:18.65

An extra 90MB of memory used for no speedup.

The image doesn't show when in the edit mode

I've installed the plug-in and I can gain the performance of image uploading. However, when I click "Edit Image" button, the preview image doesn't show and when I click "Rotate left" it show "Could not load the image. Please reload the page and try again" message. Note that the issue is disappear when I deactivate the plug-ins. Please advice me how to solve it. Thank you!!

Screen Shot 2021-04-22 at 9 17 00 AM

Screen Shot 2021-04-22 at 9 17 08 AM

Screen Shot 2021-04-22 at 9 20 06 AM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.