首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >带码点火器的图像裁剪

带码点火器的图像裁剪
EN

Stack Overflow用户
提问于 2010-08-23 20:15:41
回答 2查看 3.7K关注 0票数 1

我正在使用jcrop和codeigniter来允许用户裁剪他们上传的图像,我想要将图像裁剪到90x60大小,但是无论我尝试什么都不起作用,我当前的代码如下所示,

控制器

代码语言:javascript
运行
复制
function save_crop() {
        $this->load->library('image_lib');

        $config['image_library'] = 'gd2';
        //$config['library_path'] = '/usr/X11R6/bin/';
        $config['source_image'] = './media/images/uploads/company_uploads/' . $this->input->post('image_name');
        //$config['new_image'] = './media/images/uploads/company_uploads/cropped' . $this->input->post('image_name').'_'.time();
        //die($config['source_image']);
        $config['x_axis'] = $this->input->post('x');
        $config['y_axis'] = $this->input->post('y');
        $config['width'] = $this->input->post('w');
        $config['height'] = $this->input->post('h');
        $config['maintain_ration'] = TRUE;
        $config['dynamic_output'] = TRUE;
        $this->image_lib->initialize($config);

        if(!$this->image_lib->crop()) {
            echo $this->image_lib->display_errors();
        } else {
            echo "Success";
        }
    }

JAVASCRIPT

代码语言:javascript
运行
复制
$('#jcrop_target').Jcrop({
        onChange: showPreview,
        onSelect: showCoords,
        aspectRatio: 1,
        addClass: 'custom',
        maxSize: [90,60]
    });

    function showPreview(coords)
    {
        var rx = 100 / coords.w;
        var ry = 100 / coords.h;

        $('#preview').css({
            width: Math.round(rx * 500) + 'px',
            height: Math.round(ry * 370) + 'px',
            marginLeft: '-' + Math.round(rx * coords.x) + 'px',
            marginTop: '-' + Math.round(ry * coords.y) + 'px'
        });
    };

    function showCoords(c)
    {
        $('#x').val(c.x);
        $('#y').val(c.y);
        $('#x2').val(c.x2);
        $('#y2').val(c.y2);
        $('#w').val(c.w);
        $('#h').val(c.h);
    };

代码语言:javascript
运行
复制
<?php if(isset($upload_data)) :?>
            <?php if($upload_data['image_width'] > 90 || $upload_data['image_height'] > 60) : ?>
            <p>Your image is a little large</p>
            <form action="<?php echo base_url();?>employer/save_crop" method="post">
            <div id="uploaded_image">
                <img src="<?php echo base_url();?>media/images/uploads/company_uploads/<?php echo $upload_data['file_name'];?>" id="jcrop_target"/>
            </div>
                <div id="uploaded_preview">
                <img src="<?php echo base_url();?>media/images/uploads/company_uploads/<?php echo $upload_data['file_name'];?>" id="preview"/>
                </div>
                <input type="hidden" name="x" id="x" />
                <input type="hidden" name="y" id="y" />
                <input type="hidden" name="x2" id="x2" />
                <input type="hidden" name="y2" id="y2" />
                <input type="text" name="w" id="w" />
                <input type="text" name="h" id="h" />
                <input type="hidden" name="image_name" value="<?php echo $upload_data['file_name'];?>"/>
                <input type="submit" name="crop_image" value="Crop" />
            </form>
            <?php endif; ?>
        <?php endif; ?>
EN

Stack Overflow用户

发布于 2012-09-25 09:44:16

代码语言:javascript
运行
复制
$config['maintain_ratio'] = TRUE;

您必须将maintain_ratio而不是maintain_ration放在这里。

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3551315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档