Dynamic Image Resizer
solution: filenames without "c" (7 posts)

  1. raphaelhofer
    Posted 3 years ago #

    Plugin works great but we didn't want to change the filename convention by adding a "c" for cropped images.

    The solution:
    1) Remove the "c" from filenames
    (lines 32 and 82 remove: if ($size['crop']) $suffix .='c';)
    2) Set crop to true
    (line 22: $crop = true;)

    The joke: In WP metadata the accurate width x height is already calculated for each image format, so when you autogenerate the image later on it doesn't matter if you crop. if you crop a non-crop image you'll simply crop nothing ...


  2. Samuel Wood (Otto)
    WordPress.org Tech Dude
    Plugin Author

    Posted 3 years ago #

    If you remove the c in the filename, then hard cropped images (third parameter of add_image_size set to true) will no longer work. And if you don't use hard cropped image sizes, then the c won't be used anyway. So this change would be rather pointless.

  3. raphaelhofer
    Posted 3 years ago #

    We use both hard cropped image sizes and flexible ones:

    add_image_size( 'thumbnail', 190, 190, true );
      add_image_size( 'medium', 221, 9999, false );
      add_image_size( 'large', 640, 360, true );
      add_image_size('huge', 950, 490, true);
      add_image_size('teaser-S', 90, 90, true);
      add_image_size('teaser-M', 160, 160, true);
      add_image_size('teaser-XL', 460, 330, true);
      add_image_size( 'largetrue', 460, 9999, false );
      add_image_size( 'mr-full', 600, 9999, false );

    It works perfectly fine without the "c" and $crop set to true - just try it.
    The point is: Just crop every image even when it's not necessary, it doesn't matter - you will always get the same result.

  4. Samuel Wood (Otto)
    WordPress.org Tech Dude
    Plugin Author

    Posted 3 years ago #

    I don't think you understand what the hard cropping does. It does not give the same results as not cropping.

    If I upload an image that is 100x200, and I have add_image_size(50,100,XXX), then yes, it doesn't matter whether XXX is true or false. The image size and the actual image are proportional to one another already, so you will indeed get the same result.

    But if I upload an image that is 100x200 and I have add_image_size(50,50,XXX), then I will get different results for true and false. A value of true will hard crop and give me back a 50x50 image. A value of false will proportionally scale and give me back a 25x50 image.

    Hard cropping does what it says on the box, it hard crops the image to the center. If you don't use hard cropping, you get proportional scaling.

  5. Samuel Wood (Otto)
    WordPress.org Tech Dude
    Plugin Author

    Posted 3 years ago #

    The reason your examples don't see this, BTW, is because you are using 9999 for all the non-hard-cropping images in your example list above. You're only proportionally scaling to one parameter, making the hard crop irrelevant. Anybody else using this in the way it was intended won't have your specific needs there.

  6. raphaelhofer
    Posted 3 years ago #

    ok, to use your sample:

    upload: 100x200

    case 1: add_image_size(50,50,true) -> stores meta: imagename-50x50.jpg

    case 2: add_image_size(50,50,false) -> stores meta: imagename-25x50.jpg

    now resize both with your function on the fly with $crop=true; and you will get the pics you want ... so no "c" needed

  7. Samuel Wood (Otto)
    WordPress.org Tech Dude
    Plugin Author

    Posted 3 years ago #

    If you resize with crop=true, then you won't get the sizes you want unless you define the sizes in specific manners.

    Your case two is incorrect, basically, because right there you have $crop set to false, not true.

    Cropping and non-cropping are separate things. I can have a 50x50 image which was cropped because it was rectangular, and another 50x50 image which was not cropped because it was square, but I need to refer to them in a consistent manner. Eliminating the c eliminates the distinguishing factor and produces inconsistency among different sized images while having a standard set of resizers.

    All you've done is to set it to always hard-crop, and then to define your image sizes in a manner where they are always proportional to the images you've uploaded. This won't work universally, and the crop flag needs to be properly passed to the resizer code, via the filename.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Dynamic Image Resizer
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic