Abstract With the rapid development of digital media, QR codes have become widely used as an important medium for information transmission. However, this also presents serious security challenges, such as frequent image infringement and inevitable compression and scaling issues during data transfer. These challenges directly threaten the effectiveness and integrity of image information, and effective protection measures must be taken. Under this background, digital watermarking technology comes into being as an innovative method to enhance security. This paper presents an innovative Hybrid Particle Swarm Optimization and Gray Wolf optimization (HPG) algorithm, which combines the advantages of PSO and overcomes the limitations of traditional GWO algorithm. The algorithm is further improved by using Bernoulli chaotic mapping and nonlinear convergence factor. The experiments focus on the global and local search balance of the algorithm and its ability to resist repeated scaling attacks. The results show that the nonlinear convergence factor of HPG algorithm slows down the iteration speed at the initial stage, strengthens the global search, and avoids falling into the local optimal. In the later stage, the iteration is accelerated to improve the local search speed and convergence efficiency, thus optimizing the performance of the algorithm and ensuring the safety and quality of image information. In addition, the algorithm has better performance in balancing imperceptibility and robustness of digital watermarking, and its peak signal-to-noise ratio (PSNR) is higher. Even with many scaling iterations, the normalized correlation (NC) value is still close to 1. Compared with the existing typical algorithms, HPG algorithm is more robust to repeated scaling attacks.