[Cuis-dev] scaling an ImageMorph
Juan Vuletich
juan at cuis.st
Mon Mar 31 12:24:30 PDT 2025
Hi Hannes,
On 3/31/2025 12:48 PM, H. Hirzel via Cuis-dev wrote:
>
> Hi Juan
>
> the solution you provide is good as it is a good workaround. Looks a
> bit clumsy however constructing two ImageMorph objects as you start
> with a jpg form. And Mark wants to include this example in a booklet
> about Morphic.
>
No, #defaultForm doesn't create an ImageMorph. It just answers a sample
Form.
> Reading a JPG picture into an instance of Form, scaling it and
> constructing an ImageMorph object works fine as example [1b] in this
>
> https://lists.cuis.st/mailman/archives/cuis-dev/2025-March/010742.html
>
> thread shows.
>
> So I'd like to draw your attention that on the fact that shrinking an
> ImageMorph object does not work as example 2 in the same thread shows.
>
> The solution to make ImageMorph>>shrinkBy: work provided by
> Weslleymberg Lisboa is shown in this mail
>
> https://lists.cuis.st/mailman/archives/cuis-dev/2025-March/010745.html
>
>
> Current ImageMorph>>minimumExtent implementation
>
> ````
> minimumExtent
>
> ^ image extent + (2 * self interiorOrigin)
> ````
>
> -------------------------------------------------------------------------------------------
>
>
> Weslleymberg proposal for ImageMorph>>minimumExtent
>
> ````
> minimumExtent
>
> ^ image extent + (2 * self interiorOrigin) * self scale
>
> -------------------------------------------------------------------------------------------
>
>
> Seems to be pretty straightforward though it took him a considerable
> time to come up this it. What do you think about this solution? Are
> there side-effects about this fix? If not I suggest that it should be
> included.
>
> Kind regards
>
> Hannes
>
The problem was not in ImageMorph. There was a bug in Layout. Aux method
#minimumLayoutExtent: should work in owner's coordinates, just like
#fitInto: . I just pushed a fix that does that.
You can try this, and resize the Layout.:
A bettern implementation of ImageMorph could behave more like the Star
and the Smiley, where the Layout resize can rescale them.
Cheers,
labelMorph := LabelMorph new
contents: 'coffee';
color: Color red;
padding: 0.
aForm := ImageMorph defaultForm.
imageMorph := ImageMorph newWith: aForm.
imageMorph
borderWidth: 20;
borderColor: Color black;
scaleBy: 0.2;
padding: 0.
layoutMorph := LayoutMorph newColumn
borderWidth: 2;
borderColor: Color yellow;
padding: 0;
separation: 0;
addMorph: labelMorph;
addMorph: imageMorph;
addMorph: Sample01Star new;
addMorph: Sample03Smiley new;
"morphExtent: 300 at 300;"
openInWorld
> On 30/03/2025 8:29 pm, Juan Vuletich via Cuis-dev wrote:
>> On 3/19/2025 6:11 PM, Mark Volkmann via Cuis-dev wrote:
>>> What is the proper way (minimum code) to scale an ImageMorph?
>>> Do I have to scale both the form into which the image file is loaded
>>> AND the ImageMorph like this?
>>>
>>> filePath := '/Users/volkmannm/Pictures/images/altitude1600.jpg'.
>>> percent := 0.75.
>>> form := Form fromFileNamed: filePath :: magnifyBy: percent.
>>> morph := ImageMorph newWith: form :: scaleBy: percent.
>>>
>>> When I add this morph to a SystemWindow, the image is scaled, but
>>> there is an orange rectangle of the original size behind the image.
>>> See the attached screenshot.
>>>
>>> --
>>> R. Mark Volkmann
>>> Object Computing, Inc.
>>
>> Just scale the form prior to using it: `(ImageMorph newWith:
>> (ImageMorph defaultForm magnifyBy: 0.5)) openInWorld.`
>>
>> A new kind of morph that is not part of the BoxMorph hierarchy would
>> give better flexibility, by not using an `extent` instance variable.
>> But may be the simplest solution works for you.
>>
>> Cheers,
>> --
>> Juan Vuletich
>> cuis.st
>> github.com/jvuletich
>> researchgate.net/profile/Juan-Vuletich
>> independent.academia.edu/JuanVuletich
>> patents.justia.com/inventor/juan-manuel-vuletich
>> linkedin.com/in/juan-vuletich-75611b3
>> twitter.com/JuanVuletich
>>
--
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250331/8868f4fb/attachment.htm>
More information about the Cuis-dev
mailing list