Jump to content
horst

Croppable Image 3

Recommended Posts

Hello Horst,

thanks for your prompt answere. The page under Admin > Pages was missing. I have reinstalled the module and now everything works fine. Thanks!!!!

Share this post


Link to post
Share on other sites

@horst It's great to see croppableImage back and available again for 3.X 

Is this version here to stay or is there a risk that upcoming changes to get to 3.1 will break functionality?

Share this post


Link to post
Share on other sites

This is the version to stay. It is close to get stable 1.0.0 ! :)

The quirks with the first tries in PW3 was mainly because of misunderstandings between Ryan and me when first time talking about the changes in core image field. And also because my insuficient knowledge of PW ;)

But know we have a solution that (only) extends the core image field with additional functionality. Possible changes, enhancements on the core imagefield will automatically inherited know, like it was with the versions before the core image change.

  • Like 4

Share this post


Link to post
Share on other sites
15 hours ago, horst said:

and its now approved and available in the modules directory: http://modules.processwire.com/modules/croppable-image3/ :)

Come on, @horst! You could be a modest person, but publishing modules under different names is too much. I am used to rely on authority a bit while choosing a module to download. Your name and the vast amount of good stuff made under it has always assured me I can trust that another one new. Probable same for others. Or is some technical issue?

  • Like 1

Share this post


Link to post
Share on other sites

Simply overseen this. I think, when adding a module to the directory, most inputfields get prepopulated with the github-data, where my name is "horst-n", because "horst" wasn't available.

But I could change the module authors name to "horst". :) Thanks for pointing me to it!

Share this post


Link to post
Share on other sites

I also just removed the horst-n author name from the dropdown list of authors.

  • Like 2

Share this post


Link to post
Share on other sites

Feature request: Would it be possible to define an aspect ration (16:9, 4:3, …) instead of using px values? I have a case where I want to output different resolutions for retina/desktop/mobile/… and want to avoid a loss of resolution due to cropping (putting high px doesn't make sense either because not always the client has high resolution images at hand…)

  • Like 2

Share this post


Link to post
Share on other sites

It isn't designed to support this. But I also don't see much disadvantage for this usecase. Lets assume the width you want to support is 1400, 960, 480.

  • Setup the image field with min-width: 1400 and min-height: 788  (= 1400 / 16 * 9)
  • Create a cropsetting image16x9,
  • call it with 100% quality as master-source for the variations
$master = $page->images->first()->getCrop("image16x9", "quality=100");
$large = $master->width(1400);
$medium = $master->width(960);
$small = $master->width(480);

Or directly use the markup srcset module from @tpr and only pass the master to it!

Edited by horst
added link to markup srcset
  • Like 2

Share this post


Link to post
Share on other sites

hi horst,

just wanted to mention that  if you change an existing imagefield to croppableimage3 it will NOT show the crop settings on the input tab. after saving the field the textarea showed up correctly. maybe that could happen automatically?

thanks for one of those essential modules finally on pw3!

Share this post


Link to post
Share on other sites

I believe, saving the field before any changes can take effect is mandatory.

Share this post


Link to post
Share on other sites

sorry horst, i was unclear! of course i changed the type to croppableimage3 and SAVED it. then i looked around and around and clicked tab after tab... it was set to croppableimage3 but the textarea for the settings was not there! i cleared the cache, still not there. then i saved the field AGAIN and it finally appeared ;)

not a big deal but still worth to improve i think (if i'm not the only one experiencing this for whatever reason...)

Share this post


Link to post
Share on other sites

Enclosed you find a json file with my attempt of a GERMAN translation. Feedback is welcome (please as PM so we do not loose focus on the main topic of this thread.)

If everything's fine, I will pass it to the German language team for inclusion with the forth-coming PW V3 strings.

site--modules--croppableimage3--lang--croppableimage3textcollection-php.json

  • Like 2

Share this post


Link to post
Share on other sites

Anyone successfully using CroppableImage3 in a repeater field?

I just converted a CropImage field (used in a repeater) over to CroppableImage3 and get an error every time I try to edit any page with the repeater on now (the front end is working fine.) It's possible this is a problem with the repeater code though.

Share this post


Link to post
Share on other sites

This is resolved now. It was a problem with the underlying repeater, not the CroppableImage3 field in it. I had earlier used the API to migrate a new field into the template used by the repeater but forgot to reflect the change in the field data (specifically, the repeaterFields settings on the field.) Now I have the repeater and its template in sync, all works well. 

  • Like 2

Share this post


Link to post
Share on other sites

As promised, here's the script with delete powers. Only tested on a small subset of an installation I'm switching over to CroppableImage3 so do your own testing please!

Spoiler

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>CropImage &rArr; CroppableImage3 File Conversion</title>
    <style>
.missing     {text-decoration:line-through;}
.error       {background-color:#FDD;}
.ok          {background-color:#DFD;}
.take-action {background-color:#DDF;}
    </style>
  <head>
  <body>
    <h1>CropImage &rArr; CroppableImage3 Image File Migration</h1>
    <h2>Candidate Fields</h2>
<?php
// for PW3+
// (UPDATES by @jacmaes   bugfix for $new filename from below post!)
// (UPDATES by @netcarver debugIteration bugfix, PW3 compatibility, formatting tweaks, source file deletion switch)

$debugIteration = true;     // true to iterate only over the first page with a desired field, false to iterate over all pages
$doFilecopy     = false;    // true to really copy variation files, false for debug purposes

/** ========================= BE VERY SURE YOU WANT TO PROCEED IF SETTING THE FOLLOWING TO TRUE ========================
 * Set the following boolean to true if you want the original image variation files deleted.
 *
 * In order to prevent total loss of the images, deletion is only attempted if...
 * $doOldfileDeletion is true **AND** $doFileCopy is false **AND** the original file exists **AND** the replacement file exists
 * ========================== BE VERY SURE YOU WANT TO PROCEED IF SETTING THE FOLLOWING TO TRUE ========================*/
$doOldfileDeletion = false; // true to delete old file variations.


$oldFieldtype = 'CropImage';
$newFieldtype = 'CroppableImage3';
$timelimit = 120;  // per single page

// bootstrap PW
include(dirname(__FILE__) . '/index.php');


// collect fields and cropsetting names
$collection = array();
echo "<ul>";
foreach($fields as $f) {
    if($f->type != 'Fieldtype' . $oldFieldtype) continue;
    $collection[$f->name] = array();
    echo "<li>{$f->type} : {$f->name}</li>";
    $thumbSettings = preg_match_all('#(.*?),.*?\n#msi' , trim($f->thumbSetting) . "\n", $matches, PREG_PATTERN_ORDER);
    if(!$thumbSettings) continue;
    $collection[$f->name] = $matches[1];
    echo "<ul>";
    foreach($collection[$f->name] as $suffix) {
        echo "<li>{$suffix}</li>";
    }
    echo "</ul>";
}
echo "</ul>";
echo "<hr />";
// We also have to look at CroppableImage3 fields because, after you change your fields over, the above search won't
// find the assets that now need deleting...
echo "<ul>";
foreach($fields as $f) {
    if($f->type != 'Fieldtype' . $newFieldtype) continue;
    $collection[$f->name] = array();
    echo "<li>{$f->type} : {$f->name}</li>";
    $thumbSettings = preg_match_all('#(.*?),.*?\n#msi' , trim($f->cropSetting) . "\n", $matches, PREG_PATTERN_ORDER);
    if(!$thumbSettings) continue;
    $collection[$f->name] = $matches[1];
    echo "<ul>";
    foreach($collection[$f->name] as $suffix) {
        echo "<li>{$suffix}</li>";
    }
    echo "</ul>";
}
echo "</ul>";
echo "<hr />";

$pages_visited      = 0;
$images_visited     = 0;
$variations_visited = 0;
$variations_copied  = 0;
$variations_deleted = 0;

// now iterate over all pages and rename or copy the crop variations
echo "<h2>Asset Scan</h2>";
echo "<ul>";
foreach($pages->find("include=all") as $p) {
    set_time_limit($timelimit);  // reset the timelimit for this page
    foreach($collection as $fName => $suffixes) {
        if(!$p->$fName instanceof \ProcessWire\Pageimages) {
            continue;
        }
        $images = $p->$fName;
        if(0 == $images->count()) {
            continue;
        }
        echo "<li>Page \"<strong>{$p->title}</strong>\" <em>directory \"site/assets/files/{$p->id}/\"</em><ol>";
        foreach($images as $image) {
            echo "Image \"<strong>{$image->name}</strong>\"<ul>";
            $images_visited++;
            foreach($suffixes as $suffix) {
                $variations_visited++;
                $errors  = array();
                $dispold = "{$suffix}_" . $image->name;
              	$dispnew = str_replace(".", ".-{$suffix}.", $image->name);

                $dir = dirname($image->filename).'/';
                $old = $dir . $dispold;
                $new = $dir . $dispnew;

                $old_present = file_exists($old);
                $new_present = file_exists($new);

                /* if (!$old_present) $dispold = "<span class='missing error'>$dispold</strike> (missing)"; */
                /* if ( $new_present) $dispnew = "<span class='ok'>$dispnew</span> (present)"; */

                $old_classes = array();
                $new_classes = array();
                $msg         = '';
                if (!$old_present) $old_classes[] = 'missing';
                if (!$new_present) $new_classes[] = 'missing';

                if (!$old_present && !$new_present) {
                    // Both missing => Cannot migrate this variation, it needs to be regenerated from the original.
                    $old_classes[] = 'error';
                    $new_classes[] = 'error';
                    $msg           = '<span class="take-action">Recreate from source image</span>';
                } else if (!$old_present &&  $new_present) {
                    // Old not there, new is => All done! Migration complete
                    $msg           = '<span class="ok">Migrated</span>';
                } else if ( $old_present && !$new_present) {
                    // Old there, new not there => Ready to copy!
                    $new_classes[] = 'take-action';
                    if (!$doFilecopy) $msg = 'Ready to copy';
                } else {
                    // Both present, ready to delete old copy!
                    $old_classes[] = 'error';
                    if (!$doOldfileDeletion) $msg = 'Ready to delete original';
                }

                $old_classes = implode(' ', $old_classes);
                $new_classes = implode(' ', $new_classes);
                echo "<li><em>Variation: $suffix</em> &mdash; <span class='$old_classes'>$dispold</span> &rArr; <span class='$new_classes'>$dispnew</span> <strong>$msg</strong>";
                if($doFilecopy && $old_present && !$new_present) {
                    $res = @copy($old, $new);
                    if ($res) {
                        $variations_copied++;
                        $res = "<span class='ok'>Success</span>";
                    } else {
                        $res = "<span class='error'>FAILED</span>";
                    }
                    echo " <strong>Filecopy: $res</strong>";
                }

                if (!$doFilecopy && $doOldfileDeletion && $old_present && $new_present) {
                    $res = @unlink($old);
                    if ($res) {
                        $variations_deleted++;
                        $res = "<span class='ok'>Success</span>";
                    } else {
                        $res = "<span class='error'>FAILED</span>";
                    }
                    echo " <strong>Delete of original: $res</strong>";
                }

                echo "</li>";
            }
            echo "</ul>";
        }
        echo "</ol></li>";
        if($debugIteration) break;
    }
    $pages->uncache($p); // just in case we need the memory
    $pages_visited++;
    if($debugIteration) break;
}
echo "</ul><p>Visited $pages_visited pages.</p>";
echo "<p>Visited $images_visited images.</p>";
echo "<p>Visited $variations_visited variations.</p>";
echo "<p>Copied  $variations_copied variations.</p>";
echo "<p>Deleted $variations_deleted variations.</p>";
?>
  </body>
</html>

 

cropImage3-02.png

  • Like 5

Share this post


Link to post
Share on other sites

I finally took the plunge and installed pw 3.x... and of course CroppableImage3.... 
Honestly, CroppableImage was one of the reasons pw 3.x was a no-go for a long time.... 

I was just wondering, if the 'Crop' [from the original Image field] could be hidden somehow, since I don't want the user creating 5 different variations without purpose anyway... [or should this be asked in a different forum area?]

Excellent module nevertheless and always in my top3!

Share this post


Link to post
Share on other sites
18 minutes ago, videokid said:

Honestly, CroppableImage was one of the reasons pw 3.x was a no-go for a long time.... 

same here. but i went the risky way and it was released just in time :) i still think that this should be a core feature...

you could hide the button easily with some JS or CSS, for example using admin custom files or a little hook. do this once and you will be able to do many other little tweaks in the admin without asking for support ;)

  • Like 2

Share this post


Link to post
Share on other sites
12 minutes ago, bernhard said:

you could hide the button easily with some JS or CSS, for example using admin custom files or a little hook.

Your absolutely right! I'm already using Admin Custom Files.... I guess sometimes the obvious isn't obvious enough... :mellow:

Share this post


Link to post
Share on other sites

First of all: Great module! I just ran into one issue though, perhaps I`m doing something wrong here, but when i`m accept the image the cropped image is created and available in the assets, but in the not showing (or replacing) the image in the backend.

gif.gif

Share this post


Link to post
Share on other sites

You mean, the popup thumbnail, that appears when you hover the crop-button, isn't updated automatically when you close the editor popup window?

Share this post


Link to post
Share on other sites

Hi Horst. I mean the image itself. What I would expect is that the cropped image would replace the uploaded one so the one under homepage afbeelding in the gif. Thanks!

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...