Search

Cross section image crop: hackie instructions from dilettante ( Be aware! )

PREP:
01) download and install reflect upload filed extension
02) in the extension.driver.php comment out line 41-50
03) in the field.reflectupload.php add this:

public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null){
    if(!is_dir(DOCROOT . $this->get('destination') . '/')){
        $flagWithError = __('The destination directory, %s, does not exist.', array('<code>' . $this->get('destination') . '</code>'));
    }

    elseif(!$flagWithError && !is_writable(DOCROOT . $this->get('destination') . '/')){
        $flagWithError = __('Destination folder is not writable.') . ' ' . __('Please check permissions on %s.', array('<code>' . $this->get('destination') . '</code>'));
    }

    $label = Widget::Label($this->get('label'));
    $label->setAttribute('class', 'file');
    if($this->get('required') != 'yes') $label->appendChild(new XMLElement('i', __('Optional')));

    $span = new XMLElement('span', NULL, array('class' => 'frame'));
    if($data['file']) $span->appendChild(new XMLElement('span', Widget::Anchor('/workspace' . $data['file'], URL . '/workspace' . $data['file'])));

    $input = Widget::Input('fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix, $data['file'], ($data['file'] ? 'hidden' : 'file'));

    // add metadata for image crop
    $imageMeta = unserialize($data['meta']);
    $input->setAttribute('height', $imageMeta['height']);
    $input->setAttribute('width', $imageMeta['width']);

    $span->appendChild($input);

    $label->appendChild($span);

    // set varibales


    if($flagWithError != NULL) $wrapper->appendChild(Widget::Error($label, $flagWithError));
    else $wrapper->appendChild($label);
}



STEPS:
1) create section that would have reflectupload filed for image upload and subsection manager filed for imagecropper that uses reflectupload's field value form current section
2) new entry page for this section and note reflectupload filed's id number (inspect element > see id)

3) create section that would be managed through subsection manager
4) go to mysql of you site, find 'symfieldsimagecropper' table and go down to the last entry. You will need to edit it directly ( likely through phpmyadmin ) and manually change the value of relatedfieldid to the one obtained in the step 2

5) imagecropper.publish.js edits:

line 7 should read

$(top.window.document).ready(function() {


line 60

$upload_field = $('#field-' + o.related_field_id, parent.document).find('input'),


add below to line 71

// edit: reassign option values
o.image_file = $upload_field.attr('value');
o.image_width = $upload_field.attr('width');
o.image_height = $upload_field.attr('height');


You will have to edit mysql every time you edit subsection's fileds setting. As I mentioned I am dilettante so if anyone could tell me how to turn selectbox to input field correctly that would be great. other then that it wors and you can create a list of different crop pieces of one image.

Sorry if I missed out any relevant comments above (below) and forgive my language.

@klaftertief

I believe there is a problem with alpha-transparency on your JIT jCrop branch.

When loading a PNG through JIT mode 5 (crop) the image loses it's transparency.

When loading a PNG through JIT mode X (not crop) the image keeps it's transparency.

@klaftertief

could you point what commit of modified JIT extension I have to download in order to install Image Cropper on Symphony 2.2.5?

Thank you and happy 2013!

I guess f9e5eb7936 should work.

It worked, thank you!

Have other devs managed to use 2 imagecropper fields on one section without any issues?

Got one imagecropper for portfolio overview of entries and one for a slider and I think the cropping options are overriding each other..

I had to completely rewrite some of my own JS recently in the Address Location Field for this exact reason.

I can hazard a guess that you are right, and that the JS is expecting only one field of it's type in the markup, and therefore balking at the fact there are two.

Have other devs managed to use 2 imagecropper fields on one section without any issues?

I have about 7 or 8 of them.

Hello,

thanks for this great extension! I am trying to add the right code to my xsl file. I whish to end up with an image of the size 460 x 260. In the data source the image cropper is set up to only allow a ratio of 460 x 260.

I have an output like this:

<imagecropper cropped="yes" x1="21" x2="3264" y1="1" y2="1833" width="3243" height="1832" ratio="1.77" />

And I use this code for JIT:

<img src="/image/5/({imagecropper/@x2} - {imagecropper/@x1})/({imagecropper/@y2} - {imagecropper/@y1})/{imagecropper/@x1}/{imagecropper/@y1}/460/260/pathToMyImage/imageFileName" width="460" height="260" />

I thought it would be a good idea to calculate the width of the cropped source image (x/y2 minus x/y1). It seems that I cannot do calculations in the JIT path, can I?

Thanks for helping me! Moritz

Hello Moritz,

looking at the readme of the Image Cropper Field, I think you should write something like this for using the jCrop mode of JIT:

<img src="{$root}/image/5/{imagecropper/@width}/{imagecropper/@height}/{imagecropper/@x1}/{imagecropper/@y1}/460/260{file/@path}/{file/filename}" width="460" height="260" />

where file is a placeholder name corresponding to the Upload Field one. You can do calculations in the path, but rather than writing:

({imagecropper/@x2} - {imagecropper/@x1})

I think you should write:

{imagecropper/@x2 - imagecropper/@x1}

theBigMandarino, you are right about the calculation – thank you very much! Could you tell where I would have found this own my own so that I have a source to learn more?

You’re welcome!

You can have a look at XPath Operators or MathOps: Simple Math Operations In Xslt—in the latter you can see also some other interesting usages (round(), floor(), …).

Thanks for the two links!

Hi all,

I've been getting Internal Server Errors trying to view images cropped using this extension (with modified JIT Image Manipulation extension) on a Symphony v.2.3.2 installation. A look at my PHP error log shows the following:

PHP Catchable fatal error:  Argument 1 passed to DateTimeObj::setSettings() must be an array, null given, called in C:\Program Files (x86)\Zend\Apache2\htdocs\Project\extensions\jit_image_manipulation\lib\image.php on line 16 and defined in C:\Program Files (x86)\Zend\Apache2\htdocs\Project\symphony\lib\core\class.datetimeobj.php on line 37

Now, my knowledge of PHP unfortunately extends to the point of making matters worse, more often than not. So, first of all, is this something that's been reproduced by the rest of the community (that is to say, in v.2.3.2)? And any suggestions as to how to circumvent this issue?

Thanks in advance!

I'm also having the same error running v2.3.2 but have been unable to find a solution (also lacking php skills).

If any one knows of solution that would be great!

@davecoggins (and anybody interested)

I added require_once(CONFIG); to lib/image.php to reflect the un-modified JIT Image Manipulation extension, which seems to do the trick alright.

Hope that helps you too!

in version 2.3.3 image_file is set without path, so image could not be loaded:

https://github.com/klaftertief/imagecropper/issues/19

Hi there This topic is so active.And i've learned a lot.But i want to know that is there any free image processing control which supports to crop a batch of image in the setup of windows8?My previous one can not

Looks like the extension is not compatible with 2.3.3.

I was able to make it work (see pull request) BUT it still require modification of Custom JIT extension mentioned by @wynandkok.

Probably we have to wait for maintainer to wrap it all together.

I can confirm that this doesn't work with 2.3.5 and every possible hack tried did not solve the problem.

It seems there is both a problem with the image path and JIT returns a 500 error.

A little at a loss. Even with the path corrected, I cannot seem to make JIT work for this extension, even with the modified version.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details