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 eelkenet
      Hi! I've created a small Inputfield module called InputfieldFloatRange which allows you to use an HTML5 <input type="range" ../> slider as an InputField. I needed something like this for a project where the client needs to be able to tweak this value more based on 'a feeling' than just entering a boring old number. Maybe more people can use this so I'm hereby releasing it into the wild.  
       
      What is it?
      The missing range slider Inputfield for Processwire. 
      What does it do?
      This module extends InputfieldFloat and allows you to use HTML5 range sliders for number fields in your templates.
      It includes a visible and editable value field, to override/tweak the value if required.  
      Features
      Min/max values Precision (number of decimals) Steps (Read more) Manual override of the selected value (will still adhere to the rules above) Usage
      Clone / zip repo Install FieldtypeFloatRange, this automatically installs the Inputfield Create new field of type `Float (range)` or convert an existing `Float`, `Integer` or `Text` field. To render the field's value simply echo `$page->field` Demo
      A field with Min=0, Max=1, Step=0.2, Precision=2

      Field with settings Min=0, Max=200, Step=0.25, Precision=2

       
      Todo
      Make the display-field's size configurable (will use the Input Size field setting)  Hopefully become redundant If it's usable for others I'll add it to the Modules list  
      Changelog
      v002
      - Fix issue where setting the step value to an empty value created problem with validation
      - Make the display-field optional 
      v001
      - Initial release
       
      Thanks!
       
       
    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. Field widths entered into the Template Field Widths inputfield are only applied if the Edit Template form is submitted with the Template Field Widths inputfield in an opened state. "Collapsed" is the recommended setting if you think you might also use core inputs for setting field widths in a template context. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By adrian
      Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 35+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
    • By adrian
      This module allows you to automatically rename file (including image) uploads according to a configurable format
      This module lets you define as many rules as you need to determine how uploaded files will be named and you can have different rules for different pages, templates, fields, and file extensions, or one rule for all uploads. Renaming works for files uploaded via the admin interface and also via the API, including images added from remote URLs.   Github: https://github.com/adrianbj/CustomUploadNames
      Modules Directory: http://modules.processwire.com/modules/process-custom-upload-names/
      Renaming Rules
      The module config allows you to set an unlimited number of Rename Rules. You can define rules to specific fields, templates, pages, and file extensions. If a rule option is left blank, the rule with be applied to all fields/templates/pages/extensions. Leave Filename Format blank to prevent renaming for a specific field/template/page combo, overriding a more general rule. Rules are processed in order, so put more specific rules before more general ones. You can drag to change the order of rules as needed. The following variables can be used in the filename format: $page, $template, $field, and $file. For some of these (eg. $field->description), if they haven't been filled out and saved prior to uploading the image, renaming won't occur on upload, but will happen on page save (could be an issue if image has already been inserted into RTE/HTML field before page save). Some examples: $page->title mysite-{$template->name}-images $field->label $file->description {$page->name}-{$file->filesize}-kb prefix-[Y-m-d_H-i-s]-suffix (anything inside square brackets is is considered to be a PHP date format for the current date/time) randstring[n] (where n is the number of characters you want in the string) ### (custom number mask, eg. 001 if more than one image with same name on a page. This is an enhanced version of the automatic addition of numbers if required) If 'Rename on Save' is checked files will be renamed again each time a page is saved (admin or front-end via API). WARNING: this setting will break any direct links to the old filename, which is particularly relevant for images inserted into RTE/HTML fields. The Filename Format can be defined using plain text and PW $page variable, for example: mysite-{$page->path} You can preserve the uploaded filename for certain rules. This will allow you to set a general renaming rule for your entire site, but then add a rule for a specific page/template/field that does not rename the uploaded file. Just simply build the rule, but leave the Filename Format field empty. You can specify an optional character limit (to nearest whole word) for the length of the filename - useful if you are using $page->path, $path->name etc and have very long page names - eg. news articles, publication titles etc. NOTE - if you are using ProcessWire's webp features, be sure to use the useSrcExt because if you have jpg and png files on the same page and your rename rules result in the same name, you need to maintain the src extension so they are kept as separate files.
      $config->webpOptions = array(     'useSrcExt' => false, // Use source file extension in webp filename? (file.jpg.webp rather than file.webp) ); Acknowledgments
      The module config settings make use of code from Pete's EmailToPage module and the renaming function is based on this code from Ryan: http://processwire.com/talk/topic/3299-ability-to-define-convention-for-image-and-file-upload-names/?p=32623 (also see this post for his thoughts on file renaming and why it is the lazy way out - worth a read before deciding to use this module). 
       
       
      NOTE:
      This should not be needed on most sites, but I work with lots of sites that host PDFs and photos/vectors that are available for download and I have always renamed the files on upload because clients will often upload files with horrible meaningless filenames like:
      Final ReportV6 web version for John Feb 23.PDF

×
×
  • Create New...