Jump to content
horst

Croppable Image 3

Recommended Posts

@tpr: I added the tiny thumbs.

One little downside is, when returning back from the Modal, after creating the new Cropimage, they are not updated automatically. Only after page refresh.

screen_20170902_182100.png.8b90e9572223c0b11dd2779e4f34ff71.png

  • Like 2

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

I just use this syntax:

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

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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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 ?????

Share this post


Link to post
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:

 

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Have you modified the crop size earlier? If I remember right then the existing crops should be deleted by the module but @horst can tell the truth :)

Share this post


Link to post
Share on other sites

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

Is a Screenshot available?

Share this post


Link to post
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;">

 

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
×
×
  • Create New...