The security analysis of the existing chaotic image encryption algorithm is mainly for the algorithm whose secret keys are independent of plaintext while few crytanalysis on plaintext-related scheme is released. This paper analyzes the security of a chaotic encryption algorithm related to the sum of plaintext pixel value (SPPV). It is found that for all plaintexts with the same SPPV, the chaotic sequences used for encryption are identical. Accordingly, there exist a series of equivalent keys corresponding to the different SPPVs, a codebook attack method to crack this type of encryption algorithm is proposed. Since the SPPV is predictable, limited in number and reconfigurable, the chosen-plaintext attack is adopted to analyse the plaintext with all possible SPPVs. And the corresponding equivalent keys are calculated respectively. These equivalent keys corresponding to SPPV finally form a complete codebook for cracking the original encryption scheme. The research result shows that any encryption algorithm related to SPPV can be cracked by the codebook attack method proposed in this paper. Therefore, the method proposed in this paper owns certain universal applicability. Theoretical analysis and experimental results prove the feasibility of this method.