Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/04/2024 in all areas

  1. BIG THANKS to @UEZ for his code, which I adapted, plus adding some of my own. See his post here. I spent quite a while trying to come up with something simple to include in a program of mine. The examples in the Help file didn't quite do it for me, some very complex. Here's an image I needed to rotate by 1 degree right, and then trim and resize, for embedding into my FLAC and MP3 files for that album. The image was sourced from eBay, as alas Discogs let me down. Admittedly the album title wasn't very helpful, and there are two other volumes, though I only have the first one. Anyway, I have provided the image, so you can test and play around with it. #include <GDIPlus.au3> ; BIG THANKS to UEZ ; I modified his example from - https://www.autoitscript.com/forum/topic/155932-gdiplus-need-help-with-rotating-an-image/?do=findComment&comment=1127106 Global $hBackbuffer, $hBitmap, $hBitmap_Scaled, $hClone, $hCoverBitmap, $hCoverGC, $hCoverMatrix, $hCoverTexture, $hGraphic, $iH, $inifile, $iW, $newfile, $sCLSID $inifile = @ScriptDir & "\Settings.ini" $newfile = @ScriptDir & "\rotated.jpg" If FileExists($newfile) Then FileDelete($newfile) _GDIPlus_Startup() $hCoverTexture = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\cover.jpg") $iW = _GDIPlus_ImageGetWidth($hCoverTexture) $iH = _GDIPlus_ImageGetHeight($hCoverTexture) $iW = $iW / 2 $iH = $iH / 2 $hBitmap_Scaled = _GDIPlus_ImageResize($hCoverTexture, $iW, $iH, 5) Global $hGUI = GUICreate("", $iW, $iH) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphic) $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) $hCoverBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hBackbuffer) $hCoverGC = _GDIPlus_ImageGetGraphicsContext($hCoverBitmap) $hCoverMatrix = _GDIPlus_MatrixCreate() Rotate() Sleep(1000) Local $crop = 1, $resize = 1, $trim If $crop = 1 Then Local $lft = IniRead($inifile, "Image Crop", "left", 0) Local $tp = IniRead($inifile, "Image Crop", "top", 0) Local $wd = IniRead($inifile, "Image Crop", "width", $iW) Local $ht = IniRead($inifile, "Image Crop", "height", $iH) Local $size = $lft & "_" & $tp & "_" & $wd & "_" & $ht ; $trim = InputBox("Crop Query", "Please set the desired values." & @LF & @LF & "Left_Top_Width_Height", $size, "", 200, 160, Default, Default) If @error = 0 Then $trim = StringSplit($trim, "_", 1) If $trim[0] = 4 Then $lft = $trim[1] $tp = $trim[2] $wd = $trim[3] $ht = $trim[4] IniWrite($inifile, "Image Crop", "left", $lft) IniWrite($inifile, "Image Crop", "top", $tp) IniWrite($inifile, "Image Crop", "width", $wd) IniWrite($inifile, "Image Crop", "height", $ht) If $wd < 1 Then $wd = $iW EndIf If $ht < 1 Then $ht = $iH EndIf If $lft < 1 Then $lft = 0 EndIf If $tp < 1 Then $tp = 0 EndIf $wd = $wd - $lft $ht = $ht - $tp ; 188_55_630_496 $hClone = _GDIPlus_BitmapCloneArea($hBitmap, $lft, $tp, $wd, $ht, $GDIP_PXF24RGB) Else MsgBox(262192, "Crop Error", "Wrong number of values specified. 4 required.", 0, $DropboxGUI) EndIf EndIf Else $hClone = "none" EndIf If $resize = 1 Then If $hClone = "none" Then $hClone_Scaled = _GDIPlus_ImageResize($hBitmap, 600, 600, 5) Else $hClone_Scaled = _GDIPlus_ImageResize($hClone, 600, 600, 5) EndIf Else $hClone_Scaled = $hBitmap EndIf $sCLSID = _GDIPlus_EncodersGetCLSID("JPG") _GDIPlus_ImageSaveToFileEx($hClone_Scaled, $newfile, $sCLSID) If FileExists($newfile) Then ShellExecute($newfile) GUIDelete($hGUI) _GDIPlus_BitmapDispose($hBitmap_Scaled) _GDIPlus_BitmapDispose($hClone_Scaled) If $hClone <> "none" Then _GDIPlus_ImageDispose($hClone) _GDIPlus_MatrixDispose($hCoverMatrix) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($hCoverGC) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_BitmapDispose($hCoverBitmap) _GDIPlus_BitmapDispose($hCoverTexture) _GDIPlus_ImageDispose($hBackbuffer) _GDIPlus_Shutdown() Exit Func Rotate() _GDIPlus_GraphicsClear($hBackbuffer, 0xFF6495ED) _GDIPlus_MatrixTranslate($hCoverMatrix, 0, 0) ; move it back to 0, 0 since (112 / 2) and (37 / 2) are it's middle origin point _GDIPlus_MatrixRotate($hCoverMatrix, 1) ; rotate it around it's middle origin point (minus to rotate left) _GDIPlus_GraphicsSetTransform($hCoverGC, $hCoverMatrix) _GDIPlus_MatrixTranslate($hCoverMatrix, 0, 0) _GDIPlus_GraphicsClear($hCoverGC, 0xFFFFFFFF) ; show the GC _GDIPlus_GraphicsDrawImageRect($hCoverGC, $hCoverTexture, 0, 0, $iW, $iH) ; place the arrow at the center of it's GC _GDIPlus_GraphicsDrawImage($hBackbuffer, $hCoverBitmap, 0, 0) ; move it's GC by an offset so the image is at the correct XY using it's origin _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH) EndFunc Resulting image. Enjoy! P.S. I should have probably removed the comments by UEZ in the Rotate function, especially as I changed it to not rotate around the center. Some of the code in that function is likely redundant too, because of that change.
    1 point
  2. TheSaint

    Kobo Cover Fixer

    Or something equivalent to spaces ... whatever SciTE does. All I know, is that if I place the cursor at the start of a tab and click my right arrow, it jumps the amount of that indent value, not just a single space ... unless of course I'd made that indent a single space in program settings. To me, that indicates it is a true tab, and not just a bunch of spaces. How about you open my script and see that for yourself. P.S. Have you ever used SciTE?
    1 point
  3. TheSaint

    Kobo Cover Fixer

    Gawd, get a life. I thought you said you knew I wasn't using spaces. But I am using tabs bud. So you hijacked for no reason. Unless you are complaining that SciTE does indents wrongly? Good luck with that, as I am not about to change to another editor. If any folk are having an issue with my code, then from my point of view, the issue is them. Gawd. To TAB or NOT to TAB ... that is the question. We have a TAB here in AUS, where folk go to place bets. Peace on you too bud. You are like a light in the darkness, when the rest of us are just trying to sleep ..... Turn that bloody light out will ya. P.S. You do realize this is the Examples forum. All this if you needed to discuss it, should have been done in the Chat forum, not here.
    1 point
  4. TheDcoder

    Kobo Cover Fixer

    Yes bud, it does, I am tired of pretending that it doesn't And spaces defeat that purpose because they are inflexible unlike TABs which can be of any size depending on the user's preference. On small screens it is desirable to only have 2-character wide gap, but if your code is using spaces then you're out of luck, you have to muck around and forget about sharing your changes. Not at all bud, not at all, all coders should be aware of the implications of using spaces and tabs, that is the reason why I am kind of hijacking your thread A responsible coder should use TABs unless there is a very good reason not to. The people creating those editors are to be blamed for propagating the continued use of spaces in this modern age. So you shouldn't rely on them to pick the right approach for you. Well bud I hope you understand now, hopefully I have enlightened some of you. Peace! 🕊️ P.S. I do apologize for the momentary interruption caused by my passionate posts regarding this topic.
    1 point
  5. TheDcoder

    Kobo Cover Fixer

    Nothing really, I was just expressing my frustration of seeing people use spaces in this age Bud tell me which character is the better choice for indentation A one byte character which is purpose made for indentation and adapts to the user's preferred length on any computer A character which is not made for indentation but for separating words, has a fixed length and doesn't give a damn about the user... plus it also takes an arbitrary no. of bytes depending a 3rd party's preference which is a mere approximation of good indentation according to their specific screen size. Also it requires a special editor which will insert the N of characters when you literally press the key for the correct character should've been used instead
    1 point
  6. TheSaint

    Kobo Cover Fixer

    Okay, aside from Wertifying my code somewhat, I tweaked the BACKUP IMAGES code some more, adding another query and several feedback and logging etc improvements and fixed a few bugs I discovered. I was then able to fully test the code, and it worked well. This is the compare window in action, which popped up now and then, but mostly wasn't needed. And this was the end result. So now I am ready to tackle the new CLONE button code, though not until tomorrow now. Viewing that first screenshot, I am reminded that not only did I have several side-loaded ebooks that gave a shrunk picture within blank white picture, but that they are all gray scale for some reason. It seems side-loading them does that. No idea why? I could of course come up with a conspiracy reason, which is probably as good as any. My other memory of side-loading ebooks to my Kobo device, is that the fonts or font doesn't display properly ... uses some overlarge default or something. Anyway, we are getting there with my program and the end approaches. P.S. As can be seen from the second screenshot, around a year ago I had 308 ebooks on my Kobo device. I imagine there is at least one to two hundred more now. I saw with a few purchases last night, that I now have just over 900 ebooks at Kobo, with those not downloaded to my device being free ebooks I have picked up now and then. Those free ebooks have come via emails from BookBub or been seen in passing at the Kobo store. I may get around to reading some of them, but probably not all, so will only copy them to my device when desired. The ebooks on my device, have either been paid for or are free ones for authors I follow specifically. Those not on the device yet, are from authors I don't yet follow and maybe never will, but their free ebook appealed to me in some way, so worth checking out if I ever get the chance. P.S.S. My wife asked me the other day, to check something on her Kobo device, she has the smaller Clara HD. Anyway, while browsing it, I noticed quite a few of her ebooks were also missing covers. At this point I haven't given any thought to dealing with multiple devices with my program, but might have to come up with something. That last said, it would likely just be better to use another copy of my program in a different folder, it being fully portable after all. How often we would need or want to use my program remains to be seen. In all likelihood, every time I copy an ebook or three, at least one, perhaps all, will be missing covers or have a cover issue, depending on whether side-loaded or downloaded via Wifi. At this point I don't side-load often. WARNING - The following download is still a work-in-progress and therefor incomplete. It may give errors or more likely not do all it says yet. Kobo Cover Fixer.au3
    1 point
  7. Thanks for your suggestion @argumentum That's probably the legit solution to this, I mean a proper one. I will do the search for it and see how it goes.
    1 point
  8. Dan_555, There is a fundamental difference in how the internals of AutoIt deal with the 2 commands. I had a discussion with one of the then-developers some years ago: Dev: You don't want to use WinSetState over GUISetState on AutoIt GUI. M23: May I ask why? Dev: Because then the rest of the code wouldn't know the real state of the window and you will get unwanted (by AutoIt) behavior. Which I think is a pretty definitive statement. I would go along with Andreik's suggestion above: AutoIt GUIS = GUISetState - other GUIs - WinSetState. M23
    1 point
  9. TheDcoder

    Kobo Cover Fixer

    Who said that you were manually tying spaces? Perhaps you are unaware of the TAB character, no it's not just a shortcut key for N spaces. The real function of the "TAB" key is to insert a tabulation character, or just tab in short. It's just a single character which takes up one byte and it is specifically built to represent spaces for indentation, so instead of having files littered with a fixed amount of spaces, you could use a TAB character and simply tell your text editor program to make your TABs as wide as 4 spaces or whatever the number of spaces you'd prefer.
    0 points
×
×
  • Create New...