Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
DGrv committed Dec 26, 2024
1 parent 9b8c221 commit 2b8b166
Show file tree
Hide file tree
Showing 16 changed files with 490 additions and 169 deletions.
8 changes: 8 additions & 0 deletions _pages/code/bash.md
Original file line number Diff line number Diff line change
Expand Up @@ -977,4 +977,12 @@ done
[e-bash](https://github.com/OleksandrKucherenko/e-bash?tab=readme-ov-file#commons-functions-and-inputs)
# convert csv to html table
```sh
awk 'BEGIN {print "<table border=\"1\">"}
NR==1 {print "<tr>"; for (i=1; i<=NF; i++) print "<th>" $i "</th>"; print "</tr>"}
NR>1 {print "<tr>"; for (i=1; i<=NF; i++) print "<td>" $i "</td>"; print "</tr>"}
END {print "</table>"}' FS=, info2.csv > info.html
```
19 changes: 16 additions & 3 deletions _pages/code/magick.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ magick -density 300 -trim in.pdf -quality 100 out.png
-quality 100 sets the JPEG compression quality to the highest quality.


# crop
# crop or trim

## crop

```sh
magick input.gif -coalesce -repage 0x0 -crop WxH+X+Y +repage output.gif
Expand All @@ -102,8 +104,13 @@ You can use *qimgv* to get the dimension of the crop easily

[Source](https://stackoverflow.com/a/14036766/2444948)

## trim

Remove the white edges by trimming and setting the white background to transparent:

```sh
magick input.png -fuzz 40% -trim output.png
```



Expand Down Expand Up @@ -145,9 +152,10 @@ creating this:

![](https://dgrv.github.io/dorian-gravier/assets/images/magick_gif_01.gif)

## Option 3
## Fuzz and Transparent method

Really good results
Really good results.
This method makes pixels near white transparent. The -fuzz value determines how similar a pixel needs to be to white to be removed.

```sh
magick Bild_1c.png -fuzz 80% -transparent white Bild_1d.png
Expand All @@ -159,7 +167,12 @@ Combine with Resize, sharpen
magick Bild_1.jpg -resize 500x Bild_1b.png
magick Bild_1b.png -sharpen 0x20 Bild_1c.png
magick Bild_1c.png -fuzz 80% -transparent white Bild_1d.png
```

## Channel and Alpha

```sh
magick input.png -channel RGBA -fuzz 10% -fill none -opaque white output.png
```

# Replace color
Expand Down
12 changes: 4 additions & 8 deletions _posts/2024/2024-12-08-Video_editing_home_made_solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ I am really happy about it but for sure it is highly limited regarding creativit

Whatever




**Create issue with:**
cd C:\Users\doria\Downloads\GitHub\dorian.gravier.github.io
gh issue create --title "[Comment] Video editing home made solution" --body "" --label Comments


*to finish*
*to finish*
*to finish*
*to finish*
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: "Add margin to epub manga images for the ebook Sony PRS-T2"
date: "2024-12-19 10:54"
---

I have an old Sony PRS-T2 which works perfectly. I wanted to put some manga on it but there is this bar on the bottom with the page number that is hidding part of the images ([sometimes also text](https://www.reddit.com/r/Calibre/comments/nyfyap/sony_prst2_space_in_top_missing_text_on_bottom/), so I am not the only one with this problem).

![]({{ '/assets/images/posts/2024/manga_prs-t2/20241219-105624_Prs-t2.png' | absolute_url }})

I think there is other possibilities like css but I did not succeed really and testing was pain.

My files are .cbz in really good quality. I used [KCC (a.k.a. Kindle Comic Converter)](https://github.com/ciromattia/kcc) to convert them in epub, crop them to a specific resolution to get the maximum of it ... here the parameters I used:

![]({{ '/assets/images/posts/2024/manga_prs-t2/20241219-105328__KCC.png' | absolute_url }})

What I did then was just add some pixel at the bottom of the pictures. I used bash via WSL.

*Steps:*

- rename the epub to zip
- unzip it
- add the 100 white pixel to the bottom of each pictures
- rezip in epub

Here the source code:

```sh
#!/bin/bash -i

wd=$(pwd)
mkdir converted

for j in *epub; do

# get the names from the loop needed
filenameepub=$j
filename=$(basename "$filenameepub" .epub)
cp "$filenameepub" "${filename}.zip" # rename the epub to zip
unzip "${filename}.zip" -d "${filename}" # unzip it
cd "${filename}/OEBPS/Images" # go to the wanted directory where the pictures are

for i in *jpg; do
nname=$(basename "$i" .jpg)_temp.jpg
mv "$i" "$nname" # rename the original picture
convert "$nname" -background white -gravity south -splice 0x70 "$i" # use imagemagick to add 70px to the bottom
rm "$nname" # remove the temp picture
done

cd "${wd}/${filename}"
zip -r "../converted/${filename}_new.epub" "./" # rezip the epub
cd "$wd"
rm "${filename}.zip" # remove the temp files left
rm -r "$filename"

done
```



79 changes: 79 additions & 0 deletions _posts/2024/2024-12-24-Html_table_with_images_to_xlsx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
title: "Html table with images to xlsx with python"
date: "2024-12-24 14:53"
---

How to convert a html table with images to xlsx with those images included.
Here you have to adapt your code with input output (here info.html and info.xlsx).

```python
import os
import requests
import pandas as pd
from bs4 import BeautifulSoup
from openpyxl import Workbook
from openpyxl.drawing.image import Image
from io import StringIO


# Function to convert column index to Excel column letter(s)
def col_idx_to_excel(col_idx):
result = ''
while col_idx >= 0:
result = chr(col_idx % 26 + 65) + result
col_idx = col_idx // 26 - 1
return result


# Read the HTML file and parse it with BeautifulSoup
html_file = 'info.html' # Replace with your HTML file
with open(html_file, 'r') as file:
html_content = file.read()

# Parse the HTML with BeautifulSoup
soup = BeautifulSoup(html_content, 'html.parser')
table = soup.find('table') # Assuming there's only one table in the HTML

# Find all <img> tags and extract the URLs
img_tags = soup.find_all('img')
# Extract image sources (src attributes) and their positions
img_sources = {}
for row_idx, tr in enumerate(table.find_all('tr')):
for col_idx, td in enumerate(tr.find_all('td')):
img = td.find('img')
if img:
# Store the image source in a dictionary with (row_idx, col_idx) as the key
img_sources[(row_idx, col_idx)] = img['src']

# Create a new workbook
wb = Workbook()
ws = wb.active

# Read the HTML table and convert it to DataFrame
df = pd.read_html(StringIO(str(table)))[0]


# Write the table data to the Excel sheet
for row_idx, row in df.iterrows():
for col_idx, cell in enumerate(row):
ws.cell(row=row_idx + 1, column=col_idx + 1, value=cell)

# Replace the corresponding cells in the DataFrame with image sources
for (row_idx, col_idx), img_src in img_sources.items():
# Convert the column index to Excel-style letter(s)
col_letter = col_idx_to_excel(col_idx)
# Add the image to the corresponding cell in Excel
img = Image(img_src)
img.anchor = f'{col_letter}{row_idx}' # Adjust the cell where the image will be inserted
ws.add_image(img)

# Save the workbook
excel_file = 'info.xlsx'
wb.save(excel_file)

print(f"HTML table with images has been successfully converted to {excel_file}")

```



Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 1 addition & 20 deletions assets/images/posts/2024/rmcdufr_cut_concat_example/example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,7 @@ for k in "${arr[@]}"; do
done

cd "$oripath/output" || exit
[ -e "matrix.mp4" ] && rm "matrix.mp4"
matrixmp4

cmd.exe /c "mpv matrix.mp4 --loop-file=inf"
# cd "$oripath" || exit
# rm -r output

# # compare difference between method ffmpeg ---------------------------------------
# cd "$oripath/output" || exit
# for i in *mp4; do
# fne=$(basename $i .mp4) # get basename of file mp4
# ffmpeg -stats -v error -i $i -c copy -f framemd5 -y $fne.md5 # create the md5
# cat $fne.md5 | grep -E "^0," | awk '{print $6}' > $fne.md5 # remove the headers unwanted, filter only video, get md5 from frame
# done
# cat protocol_bfix.md5 | wc -l
# cat demuxer_bfix.md5 | wc -l
# head -1 protocol_bfix.md5
# head -1 demuxer_bfix.md5
# grep -f protocol_bfix.md5 demuxer_bfix.md5

# grep -v -f <(exiftool protocol_bfix.md5) <(exiftool demuxer_bfix.md5)
# icdiff <(exiftool protocol_bfix.md5) <(exiftool demuxer_bfix.md5)
# exiftool protocol_bfix.mp4
# rm ./*.md5 # remove the temp file and the md5
14 changes: 6 additions & 8 deletions files/Batch/FFmpeg/Fade_In_Out_v03___FFMPEG.bat
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ for %%a in (*.mp4) do (

if %sec2% lss !lengthvideo2! (
if "%what%"=="in" (
ffmpeg -stats -loglevel error -i !newfilename! -vf "fade=t=in:st=0:d=%sec%" -c:a copy %%a
ffmpeg -stats -loglevel error -i !newfilename! -vf "fade=t=in:st=0:d=%sec%" -af "afade=t=in:st=0:d=%sec%" %%a
)
if "%what%"=="out" (
ffmpeg -stats -loglevel error -i !newfilename! -vf "fade=t=out:st=!lengthvideo3!:d=%sec%" -c:a copy %%a
ffmpeg -stats -loglevel error -i !newfilename! -vf "fade=t=out:st=!lengthvideo3!:d=%sec%" -af "afade=t=out:st=!lengthvideo3!:d=%sec%" %%a
)
if "%what%"=="both" (
ffmpeg -stats -loglevel error -i !newfilename! -vf "fade=t=in:st=0:d=%sec%,fade=t=out:st=!lengthvideo3!:d=%sec%" -c:a copy %%a
ffmpeg -stats -loglevel error -i !newfilename! -vf "fade=t=in:st=0:d=%sec%,fade=t=out:st=!lengthvideo3!:d=%sec%" -af "afade=t=in:st=0:d=%sec%,afade=t=out:st=!lengthvideo3!:d=%sec%" %%a
)

) else (
echo [DEBUG] - Your video is too short to have a fade of %sec2%secm
pause
Expand Down Expand Up @@ -145,15 +144,14 @@ rename "%filename%" "%newfilename%"

if %sec2% lss %lengthvideo2% (
if "%what%"=="in" (
ffmpeg -stats -loglevel error -i "%newfilename%" -vf "fade=t=in:st=0:d=%sec%" -c:a copy "%file%"
ffmpeg -stats -loglevel error -i "%newfilename%" -vf "fade=t=in:st=0:d=%sec%" -af "afade=t=in:st=0:d=%sec%" "%file%"
)
if "%what%"=="out" (
ffmpeg -stats -loglevel error -i "%newfilename%" -vf "fade=t=out:st=%lengthvideo3%:d=%sec%" -c:a copy "%file%"
ffmpeg -stats -loglevel error -i "%newfilename%" -vf "fade=t=out:st=%lengthvideo3%:d=%sec%" -af "afade=t=out:st=%lengthvideo3%:d=%sec%" "%file%"
)
if "%what%"=="both" (
ffmpeg -stats -loglevel error -i "%newfilename%" -vf "fade=t=in:st=0:d=%sec%,fade=t=out:st=%lengthvideo3%:d=%sec%" -c:a copy "%file%"
ffmpeg -stats -loglevel error -i "%newfilename%" -vf "fade=t=in:st=0:d=%sec%,fade=t=out:st=%lengthvideo3%:d=%sec%" -af "afade=t=in:st=0:d=%sec%,afade=t=out:st=%lengthvideo3%:d=%sec%" "%file%"
)
rename temp.mp4 "%file%"
) else (
echo [DEBUG] - Your video is too short to have a fade of %sec2%sec
rename "%newfilename%" "%filename%"
Expand Down
Loading

0 comments on commit 2b8b166

Please sign in to comment.