ZLImageEditor icon indicating copy to clipboard operation
ZLImageEditor copied to clipboard

请问如何选中图片后强制crop

Open hstdt opened this issue 3 years ago • 13 comments

目前设置clipRatios需要用户手动进入编辑状态才能生效,请问如何类似于twitter选择背景那样,强制图片的比例呢?

ps: crop之后,文字如果拖动到crop范围之外,就无法拖回来了。

hstdt avatar Jun 13 '22 03:06 hstdt

比如选择完毕图片之后要先进入crop才能进行下一步操作,之后无法再次crop。可能只有单选才有这种场景。

不自己实现的原因是,如果用户自定义了半天,结果最后才crop的话,前面的功夫就白费了,体验不太好。

hstdt avatar Jun 13 '22 03:06 hstdt

ZLImageEditorConfiguration.default()
    .showClipDirectlyIfOnlyHasClipTool(true)
    .editImageTools([.clip])
    .clipRatios([.wh1x1])

这样设置即可

longitachi avatar Jun 13 '22 03:06 longitachi

非常感谢~

hstdt avatar Jun 13 '22 04:06 hstdt

记录一下,如果是使用的ZLPhotoBrowser中的ZLEditImageViewController

ZLPhotoConfiguration.resetConfiguration()
let editImageConfiguration = ZLPhotoConfiguration.default().editImageConfiguration
editImageConfiguration
    .tools([.clip])
    .clipRatios([.wh1x1])
ZLPhotoConfiguration.default()
    .editImageConfiguration(editImageConfiguration)
    .showClipDirectlyIfOnlyHasClipTool(true)
ZLEditImageViewController.showEditImageVC...

hstdt avatar Jun 21 '22 12:06 hstdt

@longitachi 如果是gif图,ZLPhotoBrowser可以选择跳过裁剪么

hstdt avatar Jun 22 '22 11:06 hstdt

Gif图不支持编辑

longitachi avatar Jun 22 '22 12:06 longitachi

@longitachi 但是如果设置showClipDirectlyIfOnlyHasClipTool为true的话,目前效果是会强制裁剪gif(使用ZLPhotoBrowser而不是直接使用ZLImageEditor,中间没有可以介入的抓手block)。如果是gif的话,能跳过这个判断么,或者把showClipDirectlyIfOnlyHasClipTool作为block。

hstdt avatar Jun 23 '22 02:06 hstdt

本来想通过canSelectAsset来实时修改showClipDirectlyIfOnlyHasClipTool(不知道能不能起作用),发现另外一个问题。

在这个场景下,editAfterSelectThumbnailImagetrue会导致canSelectAssetoperateBeforeDoneAction不会被调用,(因为这两个触发是在确定按钮上,但是被跳过了,不知道算不算是问题,还是设计如此)。而设置editAfterSelectThumbnailImagefalse又会导致crop被跳过。

let editImageConfiguration = ZLPhotoConfiguration.default().editImageConfiguration
editImageConfiguration
    .tools([.clip])
    .clipRatios([.wh1x1])

ZLPhotoConfiguration.default()
    .editImageConfiguration(editImageConfiguration)
    .navCancelButtonStyle(.image)
    .editAfterSelectThumbnailImage(true) --->  导致canSelectAsset和operateBeforeDoneAction不被调用,会比如无法控制图片大小
    .showClipDirectlyIfOnlyHasClipTool(true)   ---> 强制裁剪了gif
    .allowSelectImage(true)
    .allowSelectVideo(false)
    .maxSelectCount(1)
    .showCaptureImageOnTakePhotoBtn(false)
    .canSelectAsset { phsset in
        // Not Called
    }
    .operateBeforeDoneAction { vc, action in
        // Not Called
        action()
    }

let ac = ZLPhotoPreviewSheet()
ac.showPhotoLibrary..

hstdt avatar Jun 23 '22 02:06 hstdt

等有空了我看下,最近比较忙

longitachi avatar Jun 23 '22 02:06 longitachi

@longitachi 如果提pull request的话,选择gif的时候,更倾向于把showClipDirectlyIfOnlyHasClipTool增加一个block开放给用户,还是判断UIImage是否是GIF?

CleanShot 2022-06-23 at 10 53 31

hstdt avatar Jun 23 '22 02:06 hstdt

不提供block,判断类型

longitachi avatar Jun 23 '22 02:06 longitachi

@longitachi 按照这个思路写了一下,发现如果有需求就是允许裁剪gif的第一张图,然后拿来用,判断model/UIImage的类型就会有问题。这个是不是只能交给使用者实时来判断。

hstdt avatar Jun 23 '22 06:06 hstdt

一个不完美的workaround思路

设置saveNewImageAfterEdit为false,然后在selectImageBlock中重新通过asset将原始gif图读取出来。

hstdt avatar Jun 23 '22 06:06 hstdt