Code Monkey home page Code Monkey logo

Comments (11)

gwenzek avatar gwenzek commented on September 2, 2024

I corrected the bug.

But I should warn you that most of the time image won't be equal to image removeTransparency(white).
Indeed remove transparency convert the type of the Image to something where you can't write 'alpha' channel anymore, so the equality breaks.
If you are interested only in the value of the pixels you should compare _.pixels.toList.

It will likely be pushed soon in the maven repo, in the meanwhile you can use the stable branch of the repository.

from scrimage.

rvangsgaard avatar rvangsgaard commented on September 2, 2024

Thank you. I am trying to find ways to detect if the alpha channel is in use, and my first naive idea was to removeTransparency and check for equality. If you can recommend a way of checking for use of alpha channel, please let me know.

from scrimage.

gwenzek avatar gwenzek commented on September 2, 2024

Currently there is no constant time method to do that, because all images automatically receive an alpha channel when loaded. The alpha channel can be removed trough removeTransparency.

So in the current version I think the more efficient is:

image.pixels map( _ >> 24) forall( _ == 0xff )

It will return true when the alpha channel of the image is not used.

from scrimage.

rvangsgaard avatar rvangsgaard commented on September 2, 2024

Thanks for deploying to maven repo. On a sidenote, can you depend on a git-subfolder in SBT? I added dependency (see below), but the scrimage classes was not available. In the output I saw SBT downloaded 1.4.2, which I then switched to eventually.

lazy val scrimage = RootProject(uri("git://github.com/sksamuel/scrimage.git/core#stable"))

val main = play.Project(appName, appVersion, libraryDependencies).dependsOn(scrimage).settings(

from scrimage.

sksamuel avatar sksamuel commented on September 2, 2024

Sometimes it takes a while to appear on maven

On 27 August 2014 12:09, René Grüner Vangsgaard [email protected]
wrote:

Thanks for deploying to maven repo. On a sidenote, can you depend on a
git-subfolder in SBT? I added dependency (see below), but the scrimage
classes was not available. In the output I saw SBT downloaded 1.4.2, which
I then switched to eventually.

lazy val scrimage = RootProject(uri("git://github.com/sksamuel/scrimage.git/core#stable"))

val main = play.Project(appName, appVersion, libraryDependencies).dependsOn(scrimage).settings(


Reply to this email directly or view it on GitHub
#55 (comment).

from scrimage.

rvangsgaard avatar rvangsgaard commented on September 2, 2024

You may have misunderstood me - I am using the newest version with the fix (1.4.2) from maven, hence my thanks for deploying to maven repo :)

I did have troubles when I tried using the stable version from github, as the core is a subfolder/subproject of the root.

from scrimage.

sksamuel avatar sksamuel commented on September 2, 2024

ah ok

On 27 August 2014 12:32, René Grüner Vangsgaard [email protected]
wrote:

You may have misunderstood me - I am using the newest version with the fix
(1.4.2) from maven, hence my thanks for deploying to maven repo :)

I did have troubles when I tried using the stable version from github, as
the core is a subfolder/subproject of the root.


Reply to this email directly or view it on GitHub
#55 (comment).

from scrimage.

rvangsgaard avatar rvangsgaard commented on September 2, 2024

@gwenzek your alorithm returns false on a JPG image (notice, it is a jpeg even though it status png).

    def getImageContents(url: String): Array[Byte] = {
        import scala.language.postfixOps
        import scala.io._
        import scala.sys.process._
        import java.io.{ByteArrayOutputStream, File, InputStream}
        import java.net.URL

        val image = new ByteArrayOutputStream()
    new URL(url) #> image ! ;
    image.toByteArray
    }

scala> com.sksamuel.scrimage.Image(util.ResizeImages.getImageContents("http://i.imgur.com/7ce5j26s.png")).pixels map(_ >> 24) forall(_ == 0xff)
res8: Boolean = false

Additionally it seems like the BufferedImage.getcolorModel.isAlpha is wrong as well:

com.sksamuel.scrimage.Image(util.ResizeImages.getImageContents("http://i.imgur.com/7ce5j26s.png")).toBufferedImage.getColorModel.hasAlpha

from scrimage.

gwenzek avatar gwenzek commented on September 2, 2024

I forgot a part:

def useAlpha(img: Image): Boolean = !(img.pixels map( _ >> 24 & 0xff) forall( _ == 0xff ))

from scrimage.

gwenzek avatar gwenzek commented on September 2, 2024

9b4de9e adds a usesAlpha method to Image.

from scrimage.

rvangsgaard avatar rvangsgaard commented on September 2, 2024

Thanks - helps a pixel-ignorant like me a lot.

I am still baffled by the behaviour or the JDK method BufferedImage.getColorModel.hasAlpha on JPG a image.

from scrimage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.