Jump to content

Croppable Image 3


horst

Recommended Posts

Thank you @horst for the new tiny thumbnail. It's very useful for repeaters where the hover isn't working on them.

When I crop my predefined crop "thumbnail" it doesn't remove it's variations:

test.360x0n-thumbnail.jpg
test.480x0n-thumbnail.jpg
test.660x0n-thumbnail.jpg

Isn't the removal of CropImage children suppose to remove the above 3 variations so when the frontend page is re-visited those variations will be auto generated again with the new crop version?

Link to comment
Share on other sites

@PWaddict

My variations looks like imagename.-work-thumb.160x135.jpg, where 160x135 is added by me from api (markupsrcset module). It seems you have a different naming somehow.

@horst

You got a new PR - button preview update on new crop + prevent PW lightbox on preview img click (lightbox showed 'Error load image') + style updates

Feel free to remove the new preview button styles if you don't like it.

ci3-preview-btn.png.2d4f54c050bee8e5c3907c769b9fa21d.png

  • Like 1
Link to comment
Share on other sites

@horst I think that I found why the variations aren't removing. Their syntax is different.

Variations
test.-thumbnail.jpg (Predefined Crop)
test.-thumbnail.0x48n.jpg (New tiny thumbnail)
test.360x0n-thumbnail.jpg
test.480x0n-thumbnail.jpg
test.660x0n-thumbnail.jpg

As you can see the 360, 480 & 660 variations that I want to get removed have different syntax.

Link to comment
Share on other sites

@tpr Here is how I'm cropping them:

$thumb_medium = $photo->photos_main_photo->getCrop("thumbnail", "width=660");
$thumb_small = $photo->photos_main_photo->getCrop("thumbnail", "width=480");
$thumb_x_small = $photo->photos_main_photo->getCrop("thumbnail", "width=360");

I do not use the markupsrcset module. Is there something I could do to change the syntax or it has to be changed from the CI3 module side?

Link to comment
Share on other sites

@horst @tpr The button preview never update on a production server. On localhost it's working properly.

The cropping is broken on a production server. The area I choose to crop is always different on the Accept/Redo Crop screen. On localhost it's working properly.

I'm using the version 1.1.10 on both localhost and the server.

Link to comment
Share on other sites

11 hours ago, PWaddict said:

@tpr Here is how I'm cropping them:


$thumb_medium = $photo->photos_main_photo->getCrop("thumbnail", "width=660");
$thumb_small = $photo->photos_main_photo->getCrop("thumbnail", "width=480");
$thumb_x_small = $photo->photos_main_photo->getCrop("thumbnail", "width=360");

I do not use the markupsrcset module. Is there something I could do to change the syntax or it has to be changed from the CI3 module side?

 

11 hours ago, tpr said:

I just use this syntax:

$page->images->first()->getCrop('portrait');

I guess horst needs to fix the removal for the other syntax as well.

 

Huh! This is interesting! :o

I need to explain a bit about the naming conventions of image filenames in PW, I think.

/site/assets/files/{page-id}/basename.jpg
/site/assets/files/{page-id}/basename.0x260.jpg

/site/assets/files/{page-id}/basename.-tag1-tag2.jpg
/site/assets/files/{page-id}/basename.-tag1-tag2.200x300.jpg

/site/assets/files/{page-id}/basename.800x800.-tag5-tag3.jpg
/site/assets/files/{page-id}/basename.800x800.-tag5-tag3.200x300.jpg

Beginning after the basename, with the first dot, every dot indicates an imagevariation that also exists as a file. (only the last dot leads to the file-extension)

Every previous part in the chain is the [source | parent | original] of the actual part.

The tags chain, implemented into PW around 2.5 and made to become very robust and foolproofed by Ryan around 2.6, was meant to be used as lowercase tags, concatenated by - chars. This very restrictive usage is due the valid filename characters (lowercase), and the preserverd dot, and to prevent concatenating multiple same tagnames. (this is cleaned up to become unique in the filenames).

But this is not very userfriendly in cases like the CropNames, and the users are not aware of this restrictions why it is / would be important to follow them.

Thats why I have to handle the cropnames less restrictive. Thats also the reason why the implemented tag system in PWs imagenames cannot be used like intended. All the cool methods to get the variations of a parentimage (getVariations(), isVariation()) will fail in many cases when using images with an (invalid) tagname / cropname!

That's why I was happy to find another bulletproof solution for getting rid of the srcset variations. (Detecting the children of a crop-parent)

 

@PWaddict The way you uses it isn't an intended one. You create different INTERMEDIATE crops. The intended way is to create 1 INTERMEDIATE crop image, that serves as parent for the derived variations. But this intermediate functionality also is obsolete and will become deprecated in the next version, as it isn't much useful but leads to code bloat and confusion.

Also it sin't possible to detect derivatives of that sort. Imagine a setup with 3 cropnames: test & test-portrait & test-landscape.
As we have already read above, people do this a lot, using invalid cropnames / tagnames, with - chars or Camelcase, etc.
Now go select and create a new crop of the "test" cropname. It will errorinously also delete all variations of test-portrait and test-landscape. Also image variations that may have the cropname on another place in the filename will get deleted too.
The only way to detect variations is to keep the parent-children relation. (Blood is thicker then water, :) )

Maybe you can use it this way:

$thumb_master = $photo->photos_main_photo->getCrop("thumbnail");
$thumb_medium = $thumb_master->width(660);
$thumb_small = $thumb_master->width(480);
$thumb_x_small = $thumb_master->width(360);

This is the intended way that brings you back into sync with the system.

  • Like 3
Link to comment
Share on other sites

13 minutes ago, horst said:

 

 

Huh! This is interesting! :o

I need to explain a bit about the naming conventions of image filenames in PW, I think.


/site/assets/files/{page-id}/basename.jpg
/site/assets/files/{page-id}/basename.0x260.jpg

/site/assets/files/{page-id}/basename.-tag1-tag2.jpg
/site/assets/files/{page-id}/basename.-tag1-tag2.200x300.jpg

/site/assets/files/{page-id}/basename.800x800.-tag5-tag3.jpg
/site/assets/files/{page-id}/basename.800x800.-tag5-tag3.200x300.jpg

Beginning after the basename, with the first dot, every dot indicates an imagevariation that also exists as a file. (only the last dot leads to the file-extension)

Every previous part in the chain is the [source | parent | original] of the actual part.

The tags chain, implemented into PW around 2.5 and made to become very robust and foolproofed by Ryan around 2.6, was meant to be used as lowercase tags, concatenated by - chars. This very restrictive usage is due the valid filename characters (lowercase), and the preserverd dot, and to prevent concatenating multiple same tagnames. (this is cleaned up to become unique in the filenames).

But this is not very userfriendly in cases like the CropNames, and the users are not aware of this restrictions why it is / would be important to follow them.

Thats why I have to handle the cropnames less restrictive. Thats also the reason why the implemented tag system in PWs imagenames cannot be used like intended. All the cool methods to get the variations of a parentimage (getVariations(), isVariation()) will fail in many cases when using images with an (invalid) tagname / cropname!

That's why I was happy to find another bulletproof solution for getting rid of the srcset variations. (Detecting the children of a crop-parent)

 

@PWaddict The way you uses it isn't an intended one. You create different INTERMEDIATE crops. The intended way is to create 1 INTERMEDIATE crop image, that serves as parent for the derived variations. But this intermediate functionality also is obsolete and will become deprecated in the next version, as it isn't much useful but leads to code bloat and confusion.

Also it sin't possible to detect derivatives of that sort. Imagine a setup with 3 cropnames: test & test-portrait & test-landscape.
As we have already read above, people do this a lot, using invalid cropnames / tagnames, with - chars or Camelcase, etc.
Now go select and create a new crop of the "test" cropname. It will errorinously also delete all variations of test-portrait and test-landscape. Also image variations that may have the cropname on another place in the filename will get deleted too.
The only way to detect variations is to keep the parent-children relation. (Blood is thicker then water, :) )

Maybe you can use it this way:


$thumb_master = $photo->photos_main_photo->getCrop("thumbnail");
$thumb_medium = $thumb_master->width(660);
$thumb_small = $thumb_master->width(480);
$thumb_x_small = $thumb_master->width(360);

This is the intended way that brings you back into sync with the system.

Thank you for providing this important information regarding PW image filename conventions and a very good explanation of the reason why they exist.  It cleared things up for me, at least.

  • Like 1
Link to comment
Share on other sites

1 hour ago, PWaddict said:

@horst @tpr The button preview never update on a production server. On localhost it's working properly.

The cropping is broken on a production server. The area I choose to crop is always different on the Accept/Redo Crop screen. On localhost it's working properly.

I'm using the version 1.1.10 on both localhost and the server.

@horst I switched back to 1.1.7 and I still have the cropping problem on the server. It doesn't crop exactly the area I choose. I don't understand how is this possible to happen???? On another site on the same server with the same 1.1.7 version it crops properly.

Link to comment
Share on other sites

1 hour ago, PWaddict said:

@horst I switched back to 1.1.7 and I still have the cropping problem on the server. It doesn't crop exactly the area I choose. I don't understand how is this possible to happen???? On another site on the same server with the same 1.1.7 version it crops properly.

@horst It was the filename of the image that causing the problem. The filename was _MG_6550_copy.jpg and I changed it to test.jpg and now I can crop it properly. The button preview works too :) 

The _MG_6550_copy.jpg when uploaded it gets auto renamed to mg_6550_copy.jpg and it works fine on locahost but I don't understand why it doesn't work with that filename on the server too.  What's wrong about mg_6550_copy.jpg ?????

Link to comment
Share on other sites

26 minutes ago, PWaddict said:

The _MG_6550_copy.jpg when uploaded it gets auto renamed to mg_6550_copy.jpg and it works fine on locahost but I don't understand why it doesn't work with that filename on the server too.  What's wrong about mg_6550_copy.jpg ?????

You are local on Windows? Windows filesystem isn't case sensitive. Others are. That's why it works on windows, and that's why windows is not the best dev-platform.
So, I'm working on windows too, but have the advantage that I'm working with win-computers since back to times of DOS. (That was before Windows 3.1 :) ) Some of the restrictions from that times I'm using until today, regardless of current working platform:

  • only lowercase filenames, if there is a 1% change that a file may uploaded to webspace,
  • no spaces in filenames, - never! (Is of interest until today, if you use CLI progs somehow.)
  • ... but I'm very happy that the filename length is more than 8.3 today :lol:

 

Link to comment
Share on other sites

1 hour ago, horst said:

You are local on Windows? Windows filesystem isn't case sensitive. Others are. That's why it works on windows, and that's why windows is not the best dev-platform.
So, I'm working on windows too, but have the advantage that I'm working with win-computers since back to times of DOS. (That was before Windows 3.1 :) ) Some of the restrictions from that times I'm using until today, regardless of current working platform:

  • only lowercase filenames, if there is a 1% change that a file may uploaded to webspace,
  • no spaces in filenames, - never! (Is of interest until today, if you use CLI progs somehow.)
  • ... but I'm very happy that the filename length is more than 8.3 today :lol:

 

It might be a cache issue and not filename related.

Link to comment
Share on other sites

@horst On a different page (from the same site of course) I've upload the image with the original filename _MG_6550_copy.jpg and the cropping works properly. Also, the button preview will not always update. This is really messed up and tomorrow I have to give access to my client so he can start adding content. If he gets those issues I guess I will uninstall the module and use the core images field with the fixed crops.

Link to comment
Share on other sites

17 minutes ago, tpr said:

You mean the button preview hover image is not updating or the icon-size one on the crop button? If the latter, is there a js error? Could you share the preview img filename?

The hover on button is always displaying the correct image. The problem is on the icon-size one. I do not get any js error but sometimes I'm getting this filename: test.-thumbnail.0x48.jpg while others I'm getting this: test.-thumbnail.jpg. I noticed when it's properly working it starts with this: test.-thumbnail.jpg, then with this test.-thumbnail.jpg?v=1, then with this test.-thumbnail.jpg?v=2 but If the page refreshed and crop again it starts again with test.-thumbnail.jpg, test.-thumbnail.jpg?v=1, test.-thumbnail.jpg?v=2 but without displaying the correct image.

Link to comment
Share on other sites

Thanks, these filenames are OK at first sight, but it's the JS workaround that is failing (so it's not horst :)).

I wasn't able to entirely duplicate the issue but if I uploaded an image and set a crop without saving the page itself first, there was a JS error that prevented the preview to update (uninitialized tooltip). I've fixed it here, so please try updating this file:

https://github.com/rolandtoth/CroppableImage3/blob/master/InputfieldCroppableImage3/InputfieldCroppableImage3.js

If this doesn't help, you could hide the preview image until a better fix (eg. with some admin CSS).

  • Like 1
Link to comment
Share on other sites

12 minutes ago, tpr said:

Thanks, these filenames are OK at first sight, but it's the JS workaround that is failing (so it's not horst :)).

I wasn't able to entirely duplicate the issue but if I uploaded an image and set a crop without saving the page itself first, there was a JS error that prevented the preview to update (uninitialized tooltip). I've fixed it here, so please try updating this file:

https://github.com/rolandtoth/CroppableImage3/blob/master/InputfieldCroppableImage3/InputfieldCroppableImage3.js

If this doesn't help, you could hide the preview image until a better fix (eg. with some admin CSS).

The problem still exists. The icon-size is useful for me only on repeaters where the button hover image isn't displaying at all.

Link to comment
Share on other sites

44 minutes ago, tpr said:

Is the issue present only with repeaters?

If you mean the icon-size issue I haven't test it on repeaters. I'm just saying that if it will ever work for me it will be useful on repeaters since there is a bug there where the hover isn't triggered.

Link to comment
Share on other sites

@horst @tpr Here is why the cropping result is always different from the area I selected:

cropping_issue.thumb.jpg.c9b1e4c0747e0d99157b645fb86c875b.jpg

On the cropping modal it loads a cached image version where I previously had the image dimensions at 1244 x 829 pixels but currently it's 1400 x 933 pixels. If the non-cache image is loaded I bet it will fix the problem.

Link to comment
Share on other sites

2 hours ago, horst said:

I can't really follow what is it are you speaking of. ?

Is a Screenshot available?

Can't you see the screenshot I posted above? The modal cropping should load the non-cache version of the image with the last modified timestamp. 

Currently it loads the image like this which is wrong as here we get the very first cache version of the image with it's previously dimensions 1244 x 829 pixels:

<div class="jcrop-holder" style="width: 1244px; height: 829px; position: relative; background-color: rgb(0, 0, 0);">
<img src="/mysite/site/assets/files/1028/mg_6550_copy.jpg" style="border: none; margin: 0px; padding: 0px; position: absolute; width: 1244px; height: 829px; top: 0px; left: -139px;">
<img src="/mysite/site/assets/files/1028/mg_6550_copy.jpg" data-width="1400" data-height="1050" alt="" style="border: none; margin: 0px; padding: 0px; position: absolute; width: 1244px; height: 829px; opacity: 0.6;">

 

But since I changed the dimensions from the field settings it should be loaded like this with the current image dimensions 1400 x 933 pixels:

<div class="jcrop-holder" style="width: 1400px; height: 933px; position: relative; background-color: rgb(0, 0, 0);">
<img src="/mysite/site/assets/files/1028/mg_6550_copy.jpg?nc=1504572955" style="border: none; margin: 0px; padding: 0px; position: absolute; width: 1400px; height: 933px; top: 0px; left: -139px;">
<img src="/mysite/site/assets/files/1028/mg_6550_copy.jpg?nc=1504572955" data-width="1400" data-height="1050" alt="" style="border: none; margin: 0px; padding: 0px; position: absolute; width: 1400px; height: 933px; opacity: 0.6;">

 

Link to comment
Share on other sites

@horst I fixed the cache problem on cropping by replacing the 145 line on ProcessCroppableImage3.module with this:

'imageUrl' => $imageUrl . "?nc=" . $img->mtime,

I noticed that the Variations page is showing cached versions of my images too. I think all this is caused by Cloudflare's cache. I guess I have to find out how to disable it on the admin section of PW.

EDIT: Since the images have the same url on both frontend and backend then there is no point to disable cache on backend right? The solution would be to add "?nc=" query on the Variations images too. The Variations page belongs to the core, not to your module right?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...