Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
68 posts Page 7 of 7
Previous 1 ... 3, 4, 5, 6, 7 Next
thanks for your reply @KK - the only issue with that older version is that I don't get to see the width and height values displayed during the cropping process - which is fairly essential so that the client knows what size of image they are creating
@potato, I am PMing you a modified version of the addon.
Please test it out and let me know if it does what you require (I'll commit it to GitHub after that).

Thanks
thanks so much - tested and working - I can now see the dimensions as the image is being cropped!
Hi,
when i use the following
Code: Select all
<cms:editable order='10' group='f_img' name='gg_image' label='Image' type='image' quality='100' width='1920' enforce_max='1' />

and upload an image smaller then 1920px wide, the uploaded version remains its original size.
If i upload a larger image it resizes it to 1920px wide.

when i use this
Code: Select all
<cms:editable group='r_img' order='10'  type='jcropthumb' assoc_field='gg_image' enforce_max='1' quality=g_img_comp name='r_img_1920' width='1920' label='Responsive Image 1'  desc='1920px wide - Main Image' />

and upload a narrower image it resizes it up.
Is this the expected behaviour?
If it is, any ideas on how to change it to match that for image?
cheers
Hi,

JCropThumb ignores the 'enforce_max' directive and always tries to create a thumbnail of the specified dimension.
So, your observation matches its expected behaviour.

You may try using the type 'thumbnail' region instead if 'enforce_max' is crucial for your use-case -
https://docs.couchcms.com/tags-referenc ... nforce_max

Hope this helps.
@KK thanks for the info.
I need the jcropthumb flexibility, so i'll probably have a look at the code to see if i can mod it.
cheers
..
Free review of your code, Optimization, Help with Cart, Multilanguage, Datatables,.. anything - contact me!
Send a `Thank you!` [̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]
Couch+PHP [Couch Core PHP Q&A], HEPA [Help Pages]
Active topics [Forum posts from previous 7 days]
[edit]
I've created a modified version of jcropthumb.php with enforce_max parameter enabled.
I've also modified it to call ajax-im.php which is a rewrite of the original ajax.php but using imageMagick instead of GD.
I'm using the mods with timthumb-im.php https://www.couchcms.com/forum/viewtopic.php?f=8&t=7222#p9837.


here they are, for those interested.

jcropthumb-im.php
Code: Select all
<?php
    /*
     * jcropthumb-im.php by gwil
     * a slight mod of the following allowing enforce_max and calling ajax-im.php
     */
    /*
    The contents of this file are subject to the Common Public Attribution License
    Version 1.0 (the "License"); you may not use this file except in compliance with
    the License. You may obtain a copy of the License at
    http://www.couchcms.com/cpal.html. The License is based on the Mozilla
    Public License Version 1.1 but Sections 14 and 15 have been added to cover use
    of software over a computer network and provide for limited attribution for the
    Original Developer. In addition, Exhibit A has been modified to be consistent with
    Exhibit B.

    Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
    WARRANTY OF ANY KIND, either express or implied. See the License for the
    specific language governing rights and limitations under the License.

    The Original Code is the CouchCMS project.

    The Original Developer is the Initial Developer.

    The Initial Developer of the Original Code is Kamran Kashif (kksidd@couchcms.com).
    All portions of the code written by Initial Developer are Copyright (c) 2009, 2010
    the Initial Developer. All Rights Reserved.

    Contributor(s):

    Alternatively, the contents of this file may be used under the terms of the
    CouchCMS Commercial License (the CCCL), in which case the provisions of
    the CCCL are applicable instead of those above.

    If you wish to allow use of your version of this file only under the terms of the
    CCCL and not to allow others to use your version of this file under the CPAL, indicate
    your decision by deleting the provisions above and replace them with the notice
    and other provisions required by the CCCL. If you do not delete the provisions
    above, a recipient may use your version of this file under either the CPAL or the
    CCCL.
    */

    if ( !defined('K_COUCH_DIR') ) die(); // cannot be loaded directly

    class JCropThumb extends KUserDefinedField{

        static function handle_params( $params ){
            global $FUNCS, $AUTH;
            if( $AUTH->user->access_level < K_ACCESS_LEVEL_SUPER_ADMIN ) return;

            //
            // GWIL 20/01/19
            // + added enforce_max {default='0'} param
            $attr = $FUNCS->get_named_vars(
                array(
                    'enforce_min'=>'1',
                    'auto_refresh'=>'0',
                    'hide_assoc_preview'=>'1',
                    'enforce_max'=>'0'
                ),
                $params
            );

            $attr['enforce_min'] = ( $attr['enforce_min']==0 ) ? 0 : 1;
            $attr['auto_refresh'] = ( $attr['auto_refresh']==1 ) ? 1 : 0;
            $attr['hide_assoc_preview'] = ( $attr['hide_assoc_preview']==0 ) ? 0 : 1;
            //
            // GWIL 20/01/19
            // + added enforce_max param
            //
            $attr['enforce_max'] = ( $attr['enforce_max']==1 ) ? 1 : 0;

            return $attr;
        }

        function get_data_to_save(){
            return $this->data;
        }

        function get_search_data(){
            return;
        }

        function get_data( $for_ctx=0 ){
            global $Config;

            $data = trim( $this->data );
            if( !strlen($data) ) $data = trim( $this->default_data );

            if( $data{0}==':' ){ // if marker
                $data = substr( $data, 1 );
                $folder = ( $this->k_type=='jcropthumb' ) ? 'image' : $this->k_type;
                $domain_prefix = $Config['k_append_url'] . $Config['UserFilesPath'] . $folder . '/';
                $data = $domain_prefix . $data;
            }

            return $data;
        }

        function store_posted_changes( $post_val ){
            if( $this->auto_refresh ){
                global $FUNCS, $Config;

                $f = $this->page->_fields[$this->assoc_field];
                if( $this->deleted || $this->k_inactive || !$f || $f->deleted || $f->k_inactive ) return; // no need to store

                if( $_POST['f_'.$this->assoc_field.'_refresh'] ){
                    $f->refresh_form = 1;

                    if( $f->modified ){
                        // create thumbnail..
                        $data = '';
                        $src = $f->get_data();
                        $domain_prefix = $Config['k_append_url'] . $Config['UserFilesPath'] . 'image/';
                        if( strpos($src, $domain_prefix)===0 ){ // process image only if local
                            $src = substr( $src, strlen($domain_prefix) );
                            if( $src ){
                                $src = $Config['UserFilesAbsolutePath'] . 'image/' . $src;
                                $dest = null;
                                $w = $this->width;
                                $h = $this->height;
                                $enforce_max = $this->enforce_max;
                                $crop = ( $enforce_max ) ? 0 : 1;
                                $quality = $this->quality;

                                $thumbnail = k_resize_image( $src, $dest, $w, $h, $crop, $enforce_max, $quality );
                                if( !$FUNCS->is_error($thumbnail) ){
                                    $path_parts = $FUNCS->pathinfo( $f->get_data() );
                                    $img_path = $path_parts['dirname'] . '/';
                                    $img_path = substr( $img_path, strlen($domain_prefix) );
                                    if( $img_path ) $thumbnail = $img_path . $thumbnail;
                                    $data = ':' . $thumbnail; // add marker
                                }
                            }
                        }
                        $post_val = $data;
                    }
                }
            }

            parent::store_posted_changes( $post_val );
        }

        function validate(){

            $this->k_type = 'thumbnail';
            //$this->enforce_max = 0; // always in 'crop' mode
            return true;
        }

        function render(){
            // defunct
        }

        function _render( $input_name, $input_id, $extra1='', $dynamic_insertion=0 ){
            global $FUNCS, $CTX, $Config;

            $f = $this->page->_fields[$this->assoc_field];
            if( $f ){
                $assoc_image = $this->page->_fields[$this->assoc_field]->get_data();
            }
            $value = $this->get_data();
            if( $value ) $value .= '?='.time();
            $tb_preview = $value ? $value : K_SYSTEM_THEME_URL . 'assets/upload-image.gif';
            $tb_preview_icon = $value ? $value : K_SYSTEM_THEME_URL . 'assets/upload-image.gif';

            define( 'JCROP_URL', K_ADMIN_URL . 'addons/jcropthumb/' );
            $FUNCS->load_js( JCROP_URL . 'assets/jquery.bpopup.min.js' );
            $FUNCS->load_js( JCROP_URL . 'assets/jquery.Jcrop.min.js' );
            $FUNCS->load_css( JCROP_URL . 'assets/jquery.Jcrop.min.css' );
            $FUNCS->load_css( JCROP_URL . 'assets/jcropthumb.css' );

            if( $this->show_preview ){
                $html .= '<div class="img-preview">';
                $html .= '<a id="'.$input_id.'_preview" href="'.$tb_preview.'" class="popup-img">';
                $html .= '<img id="'.$input_id.'_tb_preview" name="'.$input_name.'_tb_preview" src="'.$tb_preview_icon.'" ';
                $html .= ( $this->preview_width ) ? 'width="'.$this->preview_width.'" ': '';
                $html .= ( $this->preview_height ) ? 'height="'.$this->preview_height.'" ': '';
                $html .= 'class="k_thumbnail_preview" >';
                $html .= $FUNCS->get_icon( 'zoom-in' );
                $html .= '</a>';
                $html .= '</div>';
            }

            if( $assoc_image && !$this->deleted && $f && !$f->deleted ){

                // check if local
                $domain_prefix = $Config['k_append_url'] . $Config['UserFilesPath'] . 'image/';
                if( strpos($assoc_image, $domain_prefix)===0 ){
                    $path = substr( $assoc_image, strlen($domain_prefix) );
                    if( $path ){
                        $local_path = $Config['UserFilesAbsolutePath'] . 'image/' . $path;
                        if( file_exists($local_path) ){

                            $info = @getimagesize($local_path);
                            if( $info!==false && intval($info[0]) && intval($info[1]) ){

                                // calculate x or y coordinate and width or height of selection rectangle to show
                                // Adapted from TimThumb script created by Tim McDaniels and Darren Hoyt with tweaks by Ben Gillbanks
                                $orig_width = intval( $info[0] );
                                $orig_height = intval( $info[1] );

                                $new_width = $this->width;
                                $new_height = $this->height;

                                if( $new_width && $new_height ){
                                    $aspect_ratio = (float) $new_width / $new_height;
                                }
                                else{
                                    if( $new_width && !$new_height ) {
                                        $new_height = round( $orig_height * ($new_width / $orig_width) );
                                        $aspect_ratio = (float) $new_width / $new_height;

                                    }elseif($new_height && !$new_width){
                                        $new_width = round( $orig_width * ($new_height / $orig_height) );
                                        $aspect_ratio = (float) $new_width / $new_height;

                                    }elseif( (!$new_width && !$new_height) || $this->no_aspect ){
                                        $aspect_ratio = 0; // allow freeform selection

                                        $new_width = $orig_width;
                                        $new_height = $orig_height;

                                    }
                                }

                                $src_x = $src_y = 0;
                                $src_w = $orig_width;
                                $src_h = $orig_height;

                                $cmp_x = $orig_width  / $new_width;
                                $cmp_y = $orig_height / $new_height;

                                if( $cmp_x > $cmp_y ){
                                    $src_w = round( ( $orig_width / $cmp_x * $cmp_y ) );
                                    $src_x = round( ( $orig_width - ( $orig_width / $cmp_x * $cmp_y ) ) / 2 );
                                }elseif ( $cmp_y > $cmp_x ){
                                    $src_h = round( ( $orig_height / $cmp_y * $cmp_x ) );
                                    $src_y = round( ( $orig_height - ( $orig_height / $cmp_y * $cmp_x ) ) / 2 );
                                }
                                $src_x2 = $src_x + $src_w;
                                $src_y2 = $src_y + $src_h;

                                $thumb_w = ( $aspect_ratio ) ? round( $new_width ) : '0';
                                $thumb_h = ( $aspect_ratio ) ? round( $new_height ) : '0';

                                $min_w = $min_h = 8;
                                if( $aspect_ratio  && $this->enforce_min ){
                                    if( $thumb_w < $src_w ){
                                        $min_w = $thumb_w;
                                        $min_h = $thumb_h;
                                    }
                                    else{
                                        $min_w = $src_w;
                                        $min_h = $src_h;
                                    }
                                }

                                // output markup
                                $html .= '<div class="crop-group"><a id="' .$input_id. '_pop_button" class="btn recreate_tb">'.$FUNCS->get_icon('reload').$FUNCS->t('recreate').'</a></div>';
                                $html .='<input type="hidden" id="' .$input_id. '_x" name="x" />';
                                $html .='<input type="hidden" id="' .$input_id. '_y" name="y" />';
                                $html .='<input type="hidden" id="' .$input_id. '_w" name="w" />';
                                $html .='<input type="hidden" id="' .$input_id. '_h" name="h" />';

                                $html .= '<div id="'.$input_id .'_pop" class="BPopup">';

                                $html .= '<img src="'. $assoc_image .'" id="'. $input_id .'_img" />';

                                $g_src = $f->get_data();
                                //
                                // GWIL 20/01/19
                                // + added $this->enforce_max param to $data
                                //      see matching changes in ajax.php
                                // -$data = base64_encode( $path )  . '|' . $thumb_w . '|' . $thumb_h . '|' . $this->quality;
                                $data = base64_encode( $g_src )  . '|' . $thumb_w . '|' . $thumb_h . '|' . $this->enforce_max . '|' . $this->quality;
                                $nonce = $FUNCS->create_nonce( 'jcrop_image_'.$data );
                                $data = $data . '|' . $nonce;

                                $html .= '<div class="crop-group field"><a href="javascript:k_jcrop_thumb(\''.$input_id.'\', \''.$data.'\')" class="btn button">'.$FUNCS->t('crop').'</a>';
                                $html .= '<span id="' .$input_id. '_wh"></span> x ';
                                $html .= '</div>';
                                $html .='</div>';

                                $html .= '<input type="hidden" id="' . $input_id . '" name="'. $input_id .'" value="'. htmlspecialchars( $this->data, ENT_QUOTES, K_CHARSET ) .'" />';

                                ob_start();
                                ?>
                                $(function(){
                                    $('#<?php echo $input_id; ?>_img').Jcrop({
                                        onChange: function(c){
                                            $('#<?php echo $input_id;?>_x').val(c.x);
                                            $('#<?php echo $input_id;?>_y').val(c.y);
                                            $('#<?php echo $input_id;?>_w').val(c.w);
                                            $('#<?php echo $input_id;?>_h').val(c.h);
                                            $('#<?php echo $input_id;?>_wh').html('w: ' + parseInt(c.w) + '&nbsp;&nbsp;h: ' + parseInt(c.h));
                                        },
                                        aspectRatio: <?php echo $aspect_ratio; ?>,
                                        setSelect:   [ <?php echo $src_x; ?>, <?php echo $src_y; ?>, <?php echo $src_x2; ?>, <?php echo $src_y2; ?> ],
                                        allowSelect: false,
                                        addClass: 'jcrop-light',
                                        bgColor: 'white',
                                        bgOpacity: .5,
                                        minSize: [<?php echo $min_w; ?>, <?php echo $min_h; ?>],
                                        boxWidth: 700,
                                        boxHeight: 700,
                                        keySupport: false
                                    });

                                    $('#<?php echo $input_id; ?>_pop_button').bind('click', function(e){

                                        // Prevents the default action to be triggered.
                                        e.preventDefault();

                                        // Triggering bPopup when click event is fired
                                        $('#<?php echo $input_id; ?>_pop').bPopup();

                                    });
                                });
                                <?php
                                $js = ob_get_contents();
                                ob_end_clean();
                                $FUNCS->add_js( $js );
                            }
                        }
                    }
                }
            }

            if( $this->auto_refresh ){
                if( $f && !$f->_jcropthumb_done && !$this->deleted && !$f->deleted ){
                    $f->_jcropthumb_done = 1;
                    $html .= '<input type="hidden" id="f_' . $this->assoc_field . '_refresh" name="f_'. $this->assoc_field .'_refresh" value="0" />';
                    ob_start();
                    ?>
                    $(function(){
                        if( !$("div#k_overlay").length ){
                            $('<div/>', {
                                id: 'k_overlay',
                            })
                            .css({
                                'filter':'alpha(opacity=60)', 'zoom':'1',
                                'opacity':'0.6',
                                'height': '100%',
                                'width': '100%',
                                'background-color': '#0b0b0b',
                                'z-index': 10000,
                                'position': 'absolute',
                                'top': 0,
                                'left': 0,
                                'display': 'none'
                            })
                            .appendTo( 'body' );
                        }
                        $('#f_<?php echo $this->assoc_field; ?>').bind('k_change', function(e){
                            $('#k_overlay').css('display', 'block');
                            var form = $('#<?php echo $CTX->get('k_cur_form', 2); ?>');
                            form.find('#f_<?php echo $this->assoc_field; ?>_refresh').val('1');
                            form.submit();
                            return false;
                        });
                    });
                    <?php
                    $js = ob_get_contents();
                    ob_end_clean();
                    $FUNCS->add_js( $js );

                    if( $this->hide_assoc_preview ){
                        $css = "#k_element_".$this->assoc_field." div.img-preview, #k_element_".$this->assoc_field." a.btn.popup-img, #k_label_f_".$this->name."{ display:none; }\r\n";
                        $css .= "#k_element_".$this->assoc_field." div.input-group.upload-group, #k_element_".$this->name." { margin-top: 0; }";
                        $css .= "#k_element_".$this->name." div.img-preview{ margin-top: -8px; }";
                        $FUNCS->add_css( $css );
                    }
                }
            }

            static $count=0;
            $count++;
            if( $count==1 ){
                ob_start();
                ?>
                function k_jcrop_thumb( field_id, data ){

                    var el_preview = '#'+field_id+'_preview';
                    var x = Math.round( $('#'+field_id + '_x').val() );
                    var y = Math.round( $('#'+field_id + '_y').val() );
                    var w = Math.round( $('#'+field_id + '_w').val() );
                    var h = Math.round( $('#'+field_id + '_h').val() );

                    var qs = '<?php echo JCROP_URL; ?>ajax-im.php?';
                    qs += 'data='+encodeURIComponent( data );
                    qs += '&x='+encodeURIComponent( x );
                    qs += '&y='+encodeURIComponent( y );
                    qs += '&w='+encodeURIComponent( w );
                    qs += '&h='+encodeURIComponent( h );

                    $.ajax({
                        dataType: "text",
                        url:      qs
                    }).done(function( response ) {
                        if( response.substr(0, 7)=='OK:http' ){

                            var popup = $('#'+field_id+'_pop');
                            popup.bPopup().close();

                            var href = response.substr(3);

                            href = href + '?rand=' + Math.random();
                            $(el_preview).attr('href', href);
                            try{
                                $('#'+field_id+'_tb_preview').attr('src', href);
                            }
                            catch( e ){}

                            //alert('<?php echo $FUNCS->t('thumb_recreated'); ?>');

                        }
                        else{
                            alert(response);
                        }
                    });
                }
                <?php
                $js = ob_get_contents();
                ob_end_clean();
                $FUNCS->add_js( $js );
            }

            return $html;
        }
    }

    // Register
    $FUNCS->register_udf( 'jcropthumb', 'JCropThumb', 0/*repeatable*/ );


ajax-im.php
Code: Select all
<?php
/*
    ajax-im.php by gwil
    Based on jcropthumb/ajax.php and the following:

    https://github.com/cheesypoof/CouchCMS-ImageMagick-Resizer

    Modified from the original source of TimThumb script created by Tim McDaniels and Darren Hoyt.
    Original license reproduced below.

    TimThumb script created by Tim McDaniels and Darren Hoyt with tweaks by Ben Gillbanks
    http://code.google.com/p/timthumb/

    MIT License: http://www.opensource.org/licenses/mit-license.php
*/
ob_start();
define( 'K_ADMIN', 1 );

if ( defined('K_COUCH_DIR') ) die( 'ajax.php is meant to be invoked directly' );
define( 'K_COUCH_DIR', str_replace( '\\', '/', dirname(dirname(dirname(realpath(__FILE__)))).'/') );

require_once( K_COUCH_DIR.'header.php' );
header( 'Content-Type: text/html; charset='.K_CHARSET );

$AUTH->check_access( K_ACCESS_LEVEL_ADMIN, 1 );

// at this point we have a logged in user with appropriate priveleges

require_once( K_COUCH_DIR.'includes/timthumb.php' );

// path to ImageMagick's convert binary
// * server *
define('K_IMAGEMAGICK_PATH', '/kunden/homepages/37/d766678654/htdocs/ImageMagick/bin/convert');


// at this point we have a logged in user with appropriate priveleges

// check to see if the exec function exists
if (!function_exists('exec')) {
    die('Error: exec does not exist - please contact your webhost');
}

$data = ( isset($_GET['data']) ) ? str_replace( ' ', '+', $_GET['data'] ) : null;
$img_x = ( isset($_GET['x']) && $FUNCS->is_natural( $_GET['x'] ) ) ? (int)$_GET['x'] : null;
$img_y = ( isset($_GET['y']) && $FUNCS->is_natural( $_GET['y'] ) ) ? (int)$_GET['y'] : null;
$img_w = ( isset($_GET['w']) && $FUNCS->is_non_zero_natural( $_GET['w'] ) ) ? (int)$_GET['w'] : null;
$img_h = ( isset($_GET['h']) && $FUNCS->is_non_zero_natural( $_GET['h'] ) ) ? (int)$_GET['h'] : null;

if( is_null($data) || is_null($img_x) || is_null($img_y) || is_null($img_w) || is_null($img_h) ){
    die( 'Invalid parameters'.' $data='.$data.' - $img_x='.$img_x.' - $img_y='.$img_y.' - $img_w='.$img_w.' - $img_h='.$img_h );
}

list( $img, $thumb_w, $thumb_h, $t_enforce_max, $t_quality, $nonce ) = explode( '|', $data );

// validate passed data not tampered with
$data = $img . '|' . $thumb_w . '|' . $thumb_h . '|' . $t_enforce_max . '|' . $t_quality;
$FUNCS->validate_nonce( 'jcrop_image_' . $data, $nonce );
$img = base64_decode( $img );

if (trim($img) == '') {
    die('Source image not set');
}

$src = $img;
$domain_prefix = $Config['k_append_url'] . $Config['UserFilesPath'] . 'image/';

$src = substr( $src, strlen($domain_prefix) );
$src = $Config['UserFilesAbsolutePath'] . 'image/' . $src;
$dest = null;
$new_width = $thumb_w;
$new_height = $thumb_h;
$enforce_max = $t_enforce_max;
$zoom_crop = ( $enforce_max ) ? 0 : 1;
$quality = $t_quality;
$crop_geometry = $img_w.'x'.$img_h.'+'.$img_x.'+'.$img_y;

// get mime type of src
$mime_type = mime_type($src);

ini_set('memory_limit', '128M');

// make sure that the src is gif/jpg/png
if (!valid_src_mime_type($mime_type)) {
    die('Invalid src mime type: ' . $mime_type);
}

if (strlen($src) && file_exists($src)) {

    // open the existing image
    $image = open_image($mime_type, $src);
    if ($image === false) {
        die('Unable to open image : ' . $src);
    }

    // get original width and height
    $width = imagesx($image);
    $height = imagesy($image);

    imageDestroy($image);

    // generate new w/h if not provided
    if ($new_width && !$new_height) {
        $new_height = $height * ($new_width / $width);
    } else if ($new_height && !$new_width) {
        $new_width = $width * ($new_height / $height);
    } else if (!$new_width && !$new_height) {
        $new_width = $width;
        $new_height = $height;
    }

    // if new dimensions cannot exceed certain values
    if ($enforce_max) {
        // the supplied width and height were actually the max permissible values
        $max_width = $new_width;
        $max_height = $new_height;

        // make the new values the same as that of the source image
        $new_width = $width;
        $new_height = $height;

        // if new dimensions already within bounds (and this not a thumbnail that we are creating), return
        if (($src==$dest) && ($new_width <= $max_width) && ($new_height <= $max_height)) {
            die();
        }

        if ($new_width > $max_width) {
            if (!$zoom_crop) {
                $ratio = (real) ($max_width / $new_width);
                $new_width = (int) ($new_width * $ratio);
                $new_height = (int) ($new_height * $ratio);
            } else {
                $new_width = $max_width;
            }
        }

        // if new height still overshoots maximum value
        if ($new_height > $max_height) {
            if (!$zoom_crop) {
                $ratio = (real) ($max_height / $new_height);
                $new_width = (int) ($new_width * $ratio);
                $new_height = (int) ($new_height * $ratio);
            } else {
                $new_height = $max_height;
            }
        }
    }

    // create filename if not provided one (happens only for thumbnails)
    if (!$dest) {
        $path_parts = $FUNCS->pathinfo($src);
        $thumb_name = $path_parts['filename'] . '-' . round($new_width) . 'x' . round($new_height) . '.' . $path_parts['extension'];
        $thumbnail = $path_parts['dirname'] . '/' . $thumb_name;

        if ($check_thumb_exists && file_exists($thumbnail)) {
            die('EXISTS:'.$thumb_name);;
        }
    }

    if ($zoom_crop) {
        $cmp_x = $width / $new_width;
        $cmp_y = $height / $new_height;

        // if new dimensions equal to the original (and this not a thumbnail that we are creating), return
        if ($src == $dest && $cmp_x == 1 && $cmp_y == 1) {
            die();
        }
    }

    if (!$dest) {
        $dest = $thumbnail;
    }

    if (@touch($dest)) {
        // give 666 permissions so that the developer can overwrite web server user
        @chmod($dest, 0666);

        $format = ($mime_type == 'image/jpeg') ? 'jpg' : (($mime_type == 'image/png') ? 'png' : 'gif');

        $transparent = ($format == 'png' || $format == 'gif') ? ' -background none' : '';

        $resize = ($cmp_x > $cmp_y) ? "x{$new_height}" : $new_width;

        // + crop the required area
        // + resize to the given width or height
        // + clear canvas
        $crop = "-crop {$crop_geometry} -resize {$resize} +repage";

        $jpg = ($format == 'jpg') ? " -debug cache -compress JPEG -define jpeg:optimize-coding=true -quality {$quality}%" : '';

        // limits in bytes: 256 MB and 228 MB
        exec(K_IMAGEMAGICK_PATH . " -limit memory 256mb -limit map 228mb -format {$format}{$transparent} {$src} {$crop}{$jpg} {$dest}");

        //die(" -limit memory 256mb -limit map 228mb -format {$format}{$transparent} {$src} {$crop}{$jpg} {$dest}");
        if( !$FUNCS->is_error($thumb_name) ) {
        $path_parts = $FUNCS->pathinfo( $img );
            $img_path = $path_parts['dirname'] . '/';
            $thumbnail_url = $img_path.$thumb_name;
        }
        // Job done. Exit.
        die( 'OK:'.$thumbnail_url);
    }
    die('NOTOK:'.$thumbnail_url);

} else {
    if (strlen($src)) {
        die('image ' . $src . ' not found');
    } else {
        die('no source specified');
    }
}


obviously a lot of cut & paste going on ;) , but glad to have it working.
cheers,
gwil
Previous 1 ... 3, 4, 5, 6, 7 Next
68 posts Page 7 of 7

Who is online

In total there are 3 users online :: 0 registered, 0 hidden and 3 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 3 guests